我能够通过名称找到我的选择元素,但是我无法找到与其关联的选定值。
以下是我的代码:
<select name="a[b]" onchange='mySelectHandler("a[b]")'>
<option value='Choice 1'>Choice 1</option>
<option value='Choice 2'>Choice 2</option>
</select>
那么,在我的处理程序中我使用了:
function mySelectHandler(name){
var mySelect = $('select[name=' + name)
// try to get selected value
// alert ("selected " + mySelect.val())
console.log("object "+ mySelect.toSource());
}
我的日志打印结果是:
对象({length:0, prevObject:{0:({}), context:({}), length:1}, context:({}), selector:"select[name=a[b]"})
有什么办法可以做到这一点吗?