我相信从下拉列表(ID 115、116和117)中选择这三个ID的方法更好:
jQuery(document).ready(function($) {
var usedNames = {};
$("select[name='item_meta[115]'] > option").each(function () {
if(usedNames[this.text]) {
$(this).remove();
} else {
usedNames[this.text] = this.value;
}
});
var usedNames = {};
$("select[name='item_meta[116]'] > option").each(function () {
if(usedNames[this.text]) {
$(this).remove();
} else {
usedNames[this.text] = this.value;
}
});
var usedNames = {};
$("select[name='item_meta[117]'] > option").each(function () {
if(usedNames[this.text]) {
$(this).remove();
} else {
usedNames[this.text] = this.value;
}
});
});
我可以使这段代码更短,并在第一个变量下选择所有ID吗?
您可以使用以选择符开头的属性
$("select[name^='item_meta'] > option")
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句