jQuery   发布时间:2022-04-19  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了带有数组表示法的复杂输入名称的jquery通配符大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有类型文本的复杂输入元素,其名称类似于产品[1] [组合] [x] [价格].这个元素有很多,名称的区别仅在于[组合]之后和[x]之后的值.

例如:

product[1][price]
product[1][combinations][x][price]
product[1][combinations][xx][price]
product[1][combinations][xxx][price]
product[1][combinations][xxxx][price]

product[1][SALE_price]
product[1][combinations][x][SALE_price]
product[1][combinations][xx][SALE_price]
product[1][combinations][xxx][SALE_price]
product[1][combinations][xxxx][SALE_price]

product[2][price]
product[2][combinations][a][price]
product[2][combinations][aa][price]
product[2][combinations][aaa][price]
product[2][combinations][aaaa][price]

product[2][SALE_price]
product[2][combinations][a][SALE_price]
product[2][combinations][aa][SALE_price]
product[2][combinations][aaa][SALE_price]
product[2][combinations][aaaa][SALE_price]

上述值x,xx,xxx,xxxx和a,aa,aaa,aaaa表示每个产品[id]的唯一值.每个组中的第一个定义(例如,产品[2] [SALE_price])表示父级或所有者产品的值,我将批量更新到其子组(组合).

我想根据存储的信息类型找到这些元素的组,例如SALE_price,然后更改其值.我不需要虑唯一值,[x]所以我希望我可以使用通配符.

我希望这样的事情可以解决问题(例子):

$("input[name='product[1][combinations][*][price]'][type='text']").val(0);

但是我猜的*不是真正的通配符,所以我不能那样使用它.

我意识到我可以做这样的事情,但是这会将0分配给所有输入而不仅仅是SALE_price:

$("input[name^='product[1][combinations]'][type='text']").val(0);

如何替换这个($(“输入[名称=’产品[1] [组合] [*] [价格]’] [类型=’文本’]”).val(0);)选择器与适当的野生卡?如果可能的话,我想保持名称数组值的顺序相同

解决方法

您可以使用多个属性选择器:

$("input[name^='product[" + number + "]'][name$='[SALE_price]']").val(0);

http://jsfiddle.net/QsVnR/

大佬总结

以上是大佬教程为你收集整理的带有数组表示法的复杂输入名称的jquery通配符全部内容,希望文章能够帮你解决带有数组表示法的复杂输入名称的jquery通配符所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。