答案 0 :(得分:4)
将opt2
放入val()
的引号中。它出现了错误,因为它是undefined
。
$('.reset').click(function () {
$('select[name=one]').val('opt2');
});
你问过其他一些方法,但我只知道另一种方法。此方法不需要jQuery运行(请注意[0]
抓取正常Object
而不是jQuery包裹Object
。)
//Without jQuery... pretty sure I'm correct with the second method, but I'm rusty on that one.
document.getElementById('formID').one.selectedIndex = 0; // Sets the select back to the first option.
document.formName.one.selectedIndex = 0;
//With jQuery
$('select[name=one]')[0].selectedIndex = 0;