来自每个相同输入ID /名称的值

编程入门 行业动态 更新时间:2024-10-26 05:18:52
本文介绍了来自每个相同输入ID /名称的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有多个 < input id =ChildidIntl1class =onlyforagetype =textname =ageperwise [1]> < / input> < input id =ChildidIntl1class =onlyforagetype =textname =ageperwise [1]>< / input> < input id =ChildidIntl1class =onlyforagetype =textname =ageperwise [1]>< / input> < input id = ChildidIntl1class =onlyforagetype =textname =ageperwise [1]>< / input> 如何从每个按钮上获取值按钮

解决方案

Quote:

< 输入 id = ChildidIntl1 cla ss = onlyforage 类型 = text name = ageperwise [1] > < / input > < 输入 id = ChildidIntl1 class = onlyforage type = text 名称 = ageperwise [1] > < / input > < 输入 id = ChildidIntl1 class = onlyforage 类型 = text name = ageperwise [1] > < / input > < 输入 id = ChildidIntl1 class = onlyforage 类型 = text name = ageperwise [1] > < / input >

首先,所有 TextBox Id 都是相同的,这是不可能的。 Id 是一个属性,应该与页面上的所有其他元素不同。 所以,如果你改变代码......

< input id = ChildidIntl1 class = onlyforage type = text 名称 = ageperwise [1] > < / input > < 输入 id = ChildidIntl2 class = onlyforage 类型 = text name = ageperwise [1] > < / input > < 输入 id = ChildidIntl3 class = onlyforage type = text name = ageperwise [ 1] > < /输入 > < input id = ChildidIntl4 class = onlyforage type = text name = ageperwise [1] > < / input >

然后获取值是简单的 jQuery 。 选择ID的价值 就像

('#ChildidIntl1')。val(); 。 演示 - [演示] Valu来自按钮上的TextBoxes的按钮 [ ^ ] 选择名称的值 如果要使用 name 属性来获取值,然后你必须在的帮助下选择每个 TextBox 属性等于选择器[name =value] [ ^ ]。 因此,代码看起来像......

var allValues = ;

(' input [name =ageperwise [1]]')。 each( function (){ allValues + =

I have multiple <input id="ChildidIntl1" class="onlyforage" type="text" name="ageperwise[1]"></input> <input id="ChildidIntl1" class="onlyforage" type="text" name="ageperwise[1]"></input> <input id="ChildidIntl1" class="onlyforage" type="text" name="ageperwise[1]"></input> <input id="ChildidIntl1" class="onlyforage" type="text" name="ageperwise[1]"></input> how to get value from each on button click

解决方案

Quote:

<input id="ChildidIntl1" class="onlyforage" type="text" name="ageperwise[1]"></input> <input id="ChildidIntl1" class="onlyforage" type="text" name="ageperwise[1]"></input> <input id="ChildidIntl1" class="onlyforage" type="text" name="ageperwise[1]"></input> <input id="ChildidIntl1" class="onlyforage" type="text" name="ageperwise[1]"></input>

First of all, all the TextBox Id are same, which can't be possible. Id is a attribute which should be different from all other elements on the page. So, if you change the code to...

<input id="ChildidIntl1" class="onlyforage" type="text" name="ageperwise[1]"></input> <input id="ChildidIntl2" class="onlyforage" type="text" name="ageperwise[1]"></input> <input id="ChildidIntl3" class="onlyforage" type="text" name="ageperwise[1]"></input> <input id="ChildidIntl4" class="onlyforage" type="text" name="ageperwise[1]"></input>

Then getting the value is easy in jQuery. Value by Selecting IDs It is like

('#ChildidIntl1').val();. Demo - [Demo] Value from TextBoxes on Button Click[^] Value by Selecting name If you want to use "name" attribute to get the value, then you have to select each of the TextBox with the help of Attribute Equals Selector [name="value"][^]. So, code would look like...

var allValues = "";

('input[name="ageperwise[1]"]').each(function(){ allValues +=

更多推荐

来自每个相同输入ID /名称的值

本文发布于:2023-10-30 18:56:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1543711.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:名称   ID

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!