我正在使用JQuery创建Web表单。
我想使用链接将先前的选择字段复制到另一个选择字段中。我改变了DOM,select1.selectedIndex的值也改变了。但是,它仍然在视觉上显示旧值。显然,您需要对其进行刷新,以便对其进行直观更新。我不了解我不断阅读的刷新方法的语法。这是我尝试执行的操作,但不起作用。
这是链接的html
<select name="entry.14.single" id="entry_14">
<option value="1"></option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option></select>
<select name="entry.16.single" id="entry_16">
<option value=1""></option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option></select>
<a href="#" onclick="setSelect('entry_16', 'entry_14');return false;">Same as above</a>
这是我的JavaScript:
function setSelect(id1, id2){
var select1 = document.getElementById(id1);
var select2 = document.getElementById(id2);
select1.selectedIndex = select2.selectedIndex;
$('#select1').selectmenu('refresh');
}
有人可以告诉我为什么我的刷新语句不起作用吗?
ps.s。我知道在同一问题上还有其他主题,我也阅读了“文档”。请不要在其他地方链接我。我读过其他资料,但没有找到我。请只告诉我要更改的内容,以使刷新正常工作。
编辑:这是一个jsfiddle,您可以在上面弄乱http://jsfiddle.net/AFzqt/7/
使用jQuery事件处理程序!
您正在寻找的功能是:
selectmenu("refresh")
在您的示例中,看起来像这样:
$(function() {
$("#changeButton").on("click", function(e) {
$("#entry_16").val($("#entry_14").val());
$("#entry_16").selectmenu("refresh");
e.preventDefault();
});
});