开发者

Howto get the Value of an Selected Object in Javascript

How Can i get the value of a开发者_开发百科n Selected object like select Id="foo" there are many options how can i get the value of the current selected?


The surest way for cross-browser support is

var foo = document.getElementById('foo');
var val = foo.options[foo.selectedIndex].value;


The currently selected option in a <select> can be retrieved by inspecting the value attribute:

Using jQuery:

$("#foo").val()

Without jQuery:

document.getElementById("foo").value


document.getElementById('foo').value
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜