开发者

Jquery Selecting Form Items Conditional on ID

开发者 https://www.devze.com 2023-03-30 17:46 出处:网络
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

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

精彩评论

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