如何使用 jQueryoption
在列表中设置值?select
我试过:
$('#SelectGroup :all').replace("tmp4", "abc");
我的意思是:搜索tmp4字符串并将其替换为abc。在列表中有 4 项我不介意直接进入 4 号入口。
我将扩展我的问题:我想传递给从外部替换值的函数。我试过:
$('#SelectGroup option').each(function(fieldNum, newVal) {
this.text = this.text.replace('tmp4',$(newVal).text());
});
});
我试过了:
$('#SelectGroup option').each(newVal, function() {
this.text = this.text.replace('tmp4',newVal);
});
});
但在这里它说它失败了!在第一行.each
为什么?你有答案吗?
我不明白!我将一个值传递给一个函数,但它在函数中失去了它的值并改变了
var newVal= $(this).val();
$('#SelectGroup option').each(function(fieldNum, newVal) {
alert("final option text is:" + $(this).text());*/
alert($(newVal).text());
this.text = this.text.replace('tmp4',$(newVal).text());
});
});
但 newVal 不是我传递给函数的 - 它是 for each 给它的