我正在jquery中使用数据表。所以我传递了一个输入类型文本框并传递了单个 id。该数据表将采用多个文本框。我将手动输入值并将其传递到 Controller 中。我想将一个或多个文本框值作为数组..
下图是我的数据表的精确 View 。 我在一处标记了红色。三个文本框的 id 相同但值不同。如何绑定(bind)那个?
function UpdateAmount() {debugger;
var id = "";
var count = 0;
$("input:checkbox[name=che]:checked").each(function () {
if (count == 0) {
id = $(this).val();
var amount= $('#Amount').val();
}
else {
id += "," + $(this).val();
amount+="," + $(this).val(); // if i give this i am getting the first text box value only.
}
count = count + 1;
});
if (count == 0) {
alert("Please select atleast one record to update");
return false;
}
真的很难找到解决方案...我想获取所有文本框值?
最佳答案
一个Id只能使用一次;使用一个类,然后当您引用该类时,您可以循环遍历它们。
<input class="getValues" />
<input class="getValues" />
<input class="getValues" />
然后,引用为...
$(".getValues")
循环作为...
var allValues = [];
var obs = $(".getValues");
for (var i=0,len=obs.length; i<len; i++) {
allValues.push($(obs[i]).val());
}
...现在您有了一个值数组。
您还可以使用 jQuery .each
功能。
var allValues = [];
var obs = $(".getValues");
obs.each(function(index, value) {
allValues.push(value);
}
关于javascript - 在 Jquery 中,从单个文本框 id 中获取不同的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29863415/