我正在尝试在表单上添加重置按钮。
代码可以工作,但它不会刷新下拉表单。所以它的值为 0,但它不显示它的新值。
如何解决这个问题?
<script>
$('#btn-reset').live('click', function() {
$("select#Wiel").selectedIndex = 0; //this works
$("select#Wiel").selectmenu({'refresh': true}); /this doesn't work
});
</script>
最佳答案
$("select#Wiel").selectedIndex = 0; // this works
不,它不起作用,因为 jQuery 对象没有 selectedIndex
属性,您应该首先将 jQuery 对象转换为 DOM 对象:
$("select#Wiel")[0].selectedIndex = 0; // this does work
或者:
document.getElementById('Wiel').selectedIndex = 0;
关于jQuery Mobile 重置下拉表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11922215/