Javascript 我需要jquery中的帮助来生成ItemName数组
这一行是用html页面编写的:Javascript 我需要jquery中的帮助来生成ItemName数组,javascript,jquery,Javascript,Jquery,这一行是用html页面编写的: <td class="item" valign="middle" align="left" width="55%"><a href="product.asp?itemid=[ITEM_CATALOGID]">[ITEM_NAME]</a> 但它覆盖了旧值并获取我们添加的last itemname。应该有For循环将所有[ITEM_NAME]存储在隐藏字段中,然后比较所有itemname而不是last itemname。 请帮帮
<td class="item" valign="middle" align="left" width="55%"><a href="product.asp?itemid=[ITEM_CATALOGID]">[ITEM_NAME]</a>
但它覆盖了旧值并获取我们添加的last itemname。应该有For循环将所有[ITEM_NAME]存储在隐藏字段中,然后比较所有itemname而不是last itemname。
请帮帮我。试试看:
var itemname = new Array();
$('input[name=coliditemnumm]').each(function(){
itemname.push($(this).val());
});
好的,试试这个
jQuery(document).ready(function(){
var item_array = [];
jQuery(".item").each(function(){
item_array.push(jQuery(this).find('a').text());
});
});
它应该做到这一点,当然在它之前包括jquery库
只添加了一个小提琴您可以用
或
的值填充数组
使用HTML类将它们全部选中:
<input type="hidden" value="[ITEM_NAME]" class="item-input" />
您将有一个
[项目名称]
的集合存储在项目中
用于比较。新数组()
与[]
相同-只是说。嗨,Guerra,我使用了相同的代码,并设置了警报(项目名称);它显示为空,并且您不需要额外的输入字段来存储值。它没有获取[ITEM_NAME]。是否有任何错误?你可以在这把小提琴上看到这一点:
jQuery(document).ready(function(){
var item_array = [];
jQuery(".item").each(function(){
item_array.push(jQuery(this).find('a').text());
});
});
<input type="hidden" value="[ITEM_NAME]" class="item-input" />
var items = []
$('.item-input').each(function() {
items.push($(this).val())
})