开发者

disable control using jQuery

I wa开发者_如何学Cnt to disable control on click for this i have added attr to the control 'disabled' and it is working fine in IE but not in Firefox. The code i have written is

$(obj).attr('disabled','disabled');

If I am missing something then please give me idea.


$(obj).attr('disabled', true);


Try this

$(obj).attr("disabled","disable")

note value of attribute "disabled" is "disable" not "disabl*ed*"


This is the code I use to disable or re-enable a control:

function handleControlDisplay(className, foundCount, checked) {



    var button = jQuery(className);



    if (foundCount > 0 && foundCount == checked) {

        // enable

        button.removeAttr("disabled");

    }

    else {

        // set the disabled attribute

        button.attr("disabled", "true");

    };

}


The very complete answer is here: Disable/enable an input with jQuery?

TL;DR use the .prop() method

$("input").prop('disabled', true);
$("input").prop('disabled', false);


Here's an example of disabling a button after it has been clicked. Notice that you pass the "this" object to the click event handler :

<input type="button" value="Submit" onclick="disable(this)"/>

And the javascript:

    <script>
     function disable(control){
       control.disabled = true;
      }
   </script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜