jQuery input prob disable false by clicking the input

假装没事ソ 提交于 2019-12-11 09:47:29

问题


i want by clicking on an input element, that the prop, "disabled" is getting false, but this is not working.

to set all input on .ready to "disabled" -> true is working.

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

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

SOLUTION / EDIT (sorry I am not allowed to use the answer-button on my own question):

I found a better solution. Using "readonly" instead of "disabled" does the job.

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

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

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

 });
</script>

回答1:


Seems like your logic is reverted. Disabled=true means actually that element is disabled (not clickable). Try this way:

$(document).ready(function() {

   $(this).removeProp("disabled");      

   $("input").click(function() { 
        $("input").prop("disabled", "disabled"); 
    });

});


来源:https://stackoverflow.com/questions/18485231/jquery-input-prob-disable-false-by-clicking-the-input

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!