当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Selecting a form that doesn't have two or more names

问题描述:

I'm selecting a form that doesn't have the name "someform", like this:

 $("form[name!=someform]").bind("keyup", function(e){

[some code]

});

What if I want to select a form that doesn't have multiple names, like "someform1" or "someform2"?

How do I do that?

网友答案:

Just supply multiple attribute selectors.

$("form[name!=someform1][name!=someform2]").bind("keyup", function(e){ [some code] });

Although it would be easier to apply classes to distinguish different forms and use those.

$("form.ajax-form").bind(...);
网友答案:

Im afraid you have to make that distinction before you handle the rest of the code.

Depending on the situation you can always make an exeption for something thats radically different to the rest of your system.

Anyway, make an array, check if the array contains the formname.

网友答案:

You can either use another attribute like it's id or class or you can use the element itself:

If you have one:

$("form").bind(("keyup", function(e){
    [some code]
});

Or with more than one:

$("form:eq(0)").bind(("keyup", function(e){ //eq is the form index you're selecting
    [some code]
});
网友答案:

http://api.jquery.com/not/

$('form').not('form[name=someform] form[name=someform2]').bind( ... )
分享给朋友:
您可能感兴趣的文章:
随机阅读: