开发者

Multiple Forms on a Single Page - JQuery

开发者 https://www.devze.com 2023-01-25 23:09 出处:网络
I have multiple forms on a single page with the same named variables within each form. I need to be able to changed the specific values for one form but not the others.

I have multiple forms on a single page with the same named variables within each form.

I need to be able to changed the specific values for one form but not the others.

Ie.

I want to be able to set the value of Var2 for form2, but not the values of Var2 for form1.

Any ideas?

开发者_开发百科

Thanks


Ideally, give the forms their own IDs and use the Descendant Selector:

$("#form1 input[name=foo]").val("something");

or select it by the order in which it appears in the DOM using eq (as Alxandr points out):

$("form:eq(0) input[name=foo]").val("something"); // select the first form
0

精彩评论

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