开发者

Jquery Selecting Form Items Conditional on ID

I have a form and I want to disable all the Elements that do not match a given ID using jquery

here is the basic logic I'm trying to ac开发者_JAVA百科hieve

for (AllElementsInthisForm){

    if(formElementID != specificid)
    {
       disable
    }
}

I hope that makes sense. Any ideas?


There is a :not selector.

$('#FORMID input:not(#IDNAME)').attr('disabled', 'disabled');

Or an alternative sytax which is suitable for more complex conditions:

$('#FORMID input:not([id=IDNAME])').attr('disabled', 'disabled');

http://jsfiddle.net/wMUsg/


$('#form input:not(#excludeID)').attr("disabled", true);


A class would make more sense in your case.

<div class="disableThis" />
<a class="disableThis />

<script>
    $('.disableThis').attr('disabled', 'disabled');
</script>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜