我想在单击时向列中添加一个按钮,将当前页面上的所有其他下拉项目设置为所做的选择。
<select class="select2 select2-offscreen" id="id[0]" name="id[0]">
<option value="not received">Not Received</option>
<option value="received">Received</option>
</select>
<select class="select2 select2-offscreen" id="id[1]" name="id[1]">
<option value="not received">Not Received</option>
<option value="received">Received</option>
</select>
<select class="select2 select2-offscreen" id="id[2]" name="id[2]">
<option value="not received">Not Received</option>
<option value="received">Received</option>
</select>
<button class="go-btn" type="submit">Update All</button>
JS:
$('.go-btn').click(function() {
$("select option").each(function() {
//how to update the dropdow?
});
});
答案 0 :(得分:3)
这是你在找什么? https://jsfiddle.net/zmbagh9h/3/
var lastSelectedValue = 'not received';
$('select').change(function() {
lastSelectedValue = this.value;
});
$('.go-btn').click(function() {
$('select').val(lastSelectedValue);
});