【发布时间】:2010-09-05 03:52:11
【问题描述】:
【问题讨论】:
标签: javascript jquery forms select
【问题讨论】:
标签: javascript jquery forms select
将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;
【讨论】:
"enclosing in quotes or doublequotes still doesn't work" 那么代码中存在一个问题,您没有向我们展示。链接到重复新问题的页面或发布代码。