简体   繁体   English

如果单击其他内容-更改prop / jQuery

[英]If clicking something else - change prop / jQuery

if clicking something else, the last input (which was clicked) should be readonly -> true again. 如果单击其他内容,则最后一次输入(已单击)应再次为只读-> true。

here is my code: 这是我的代码:

<script>
  $(document).ready(function() {

   $("input").prop("readonly", true);      

   $("input").click(function() { 
        $(this).prop("readonly", false); 
    });

  });
</script>

thanks! 谢谢!

try this 尝试这个

--to make input editable on click
    $('input').bind('click', function () {
        $(this).prop("readonly", false);
    });

--to make input readonly on lost focus
    $('input').bind('blur', function () {
        $(this).prop("readonly", true);  
    });
$("input").click(function() {
    var $that = $(this);
    $("input").each(function() {
       if ($(this) !== $that) {
          $(this).prop("readonly", false);
       }
    });    
});

尝试

$("input").attr("readonly", "readonly");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM