如何让第一个选项被选中?我尝试过这个但不起作用:
selectElement.options[0].selected=true;
它给了我这个错误:
Uncaught TypeError: Cannot read property '0' of undefined
更新
解决了!通过正确定义 selectElement。
最佳答案
试试这个
document.getElementById('mySelect').selectedIndex = 0;
关于javascript - 重置选择元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9141939/