//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;
Put opt2 in quotes for val(). It's coming up as an error because it is undefined.
You asked for some other methods, but I only know of one other. This method doesn't require jQuery to function (note that the [0] grabs the normal Object rather than an jQuery wrapped 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;
发布评论
评论(1)
将
opt2
放在val()
的引号中。它会作为错误出现,因为它是未定义
。你问了一些其他的方法,但我只知道另一种。此方法不需要 jQuery 来运行(请注意,
[0]
获取普通的Object
,而不是 jQuery 包装的Object
)。Put
opt2
in quotes forval()
. It's coming up as an error because it isundefined
.You asked for some other methods, but I only know of one other. This method doesn't require jQuery to function (note that the
[0]
grabs the normalObject
rather than an jQuery wrappedObject
).