【问题标题】:If clicking something else - change prop / jQuery如果单击其他内容 - 更改 prop / jQuery
【发布时间】:2013-08-28 19:29:04
【问题描述】:

如果点击其他内容,最后一个输入(被点击的)应该是只读的 -> 再次为真。

这是我的代码:

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

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

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

  });
</script>

谢谢!

【问题讨论】:

标签: jquery input click prop


【解决方案1】:

试试这个

--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);  
    });

【讨论】:

  • 干得好 - 谢谢 - 但仍然无法在 iOS 上工作 link
【解决方案2】:
$("input").click(function() {
    var $that = $(this);
    $("input").each(function() {
       if ($(this) !== $that) {
          $(this).prop("readonly", false);
       }
    });    
});

【讨论】:

    【解决方案3】:

    试试

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

    【讨论】:

      猜你喜欢
      • 2013-09-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-20
      • 2012-09-08
      • 1970-01-01
      • 1970-01-01
      • 2014-06-21
      • 1970-01-01
      相关资源
      最近更新 更多