我在这里错过了什么?
作为对 How can i change options in dropdowns if it is generated dynamically? 的回答的一部分
我在 onchange 中遇到问题。我想将所有 sibling 的值设置为更改后的 select 的值
$("select").on("change",function() {
var idx=$(this).val();
console.log($(this).attr("id"),$(this).val())
$(this).siblings("select").each(function() {
$(this).val(idx);
});
});
这是在 JSFIDDLE 中生成的代码
我见过
How do i get the value of all other dropdowns when one of them is changed
但我更愿意找出错误的原因
最佳答案
您正在使用 val
方法作为属性。
var idx=$(this).val;
// ----^
您还可以使用 val
方法代替 each
:
$("select").on("change", function() {
$(this).siblings("select").val(this.value);
});
关于javascript - sibling 给对象 #<HTMLSelectElement> 没有方法 'each',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12874726/