2013-09-27 53 views
0

的价值我有一个选择框,我试图让所选选项的值。我得到的对象#的错误地产 '价值' 不是一个函数试图捕捉选择的选项

HTML:

<select id="my_SiteUsers" style="width:350px;" onchange="RefreshGroupLists()"> 
<option 
    value="i:0#.w|itun\akondruss_fg">Alex</option> 
<option value="i:0#.w|itun\allepage_fg">Alex</option> 
</select> 

enter image description here

JS:

var e = document.getElementById("my_SiteUsers"); 
    var user = e.value(); 
    alert(user); 

回答

2

value不是一个函数,它的DOM节点的属性:

var e = document.getElementById("my_SiteUsers"); 
var user = e.value; 
alert(user); 

或使用jQuery:

var user = $('#my_SiteUsers').val(); 
+0

谢谢你,成功了! – Batman

0

尝试使用jQuery的.VAL(),就像很多JQ功能,这将是(可能)不是通过JS要容易得多。

// Get the value from a dropdown select 
$("select.foo option:selected").val(); 

文档:http://api.jquery.com/val/

edit--看起来像上面的解决方案解决了这个问题更容易:)