【问题标题】:jQuery input prob disable false by clicking the inputjQuery input prob 通过单击输入禁用 false
【发布时间】:2013-08-31 08:51:26
【问题描述】:

我希望通过单击输入元素,道具“已禁用”变得错误,但这不起作用。

将 .ready 上的所有输入设置为“已禁用”-> true 有效。

<script>
$(document).ready(function() {
  $("input").prop("disabled", true); // this is working
});

$("input").click(function() { 
 $(this).prop("disabled", false); // this is not working
});
</script>

解决方案/编辑(抱歉,我不允许在自己的问题上使用答案按钮):

我找到了更好的解决方案。 使用“只读”而不是“禁用”就可以了。

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

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

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

 });
</script>

【问题讨论】:

    标签: jquery input click


    【解决方案1】:

    好像你的逻辑被颠倒了。 Disabled=true 实际上意味着该元素被禁用(不可点击)。试试这个方法:

    $(document).ready(function() {
    
       $(this).removeProp("disabled");      
    
       $("input").click(function() { 
            $("input").prop("disabled", "disabled"); 
        });
    
    });
    

    【讨论】:

    • @Itay 看起来你是对的,但它是如何工作的,如果它们处于 disabled 状态,输入将不会启动 click 事件
    • @Mike 现在看看我的回答
    • 也许还有一种方法可以让自定义变量说它被禁用,如果它被“禁用”则 preventDefault。 P.S - 看起来很奇怪的行为
    • 是的,但至少它会起作用 :) 我认为这种行为的整个要求应该由 OP 重新考虑
    • @Chrniv 它的工作原理——但反过来。 1) 禁用 2) 点击 3) 未禁用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多