Simple jQuery: Why does this not work?
T开发者_开发技巧he value is always undefined (Chrome 12.0.742.112). The .get() does return an HTML input object but accessing value is undefined.
<input id="a" value="abc" onkeyup="b()" />
<script src="jquery.js"></script>
<script>
function b() {
alert($('#a').get().value);
}
</script>
However using standard JS works (as does .val()):
document.getElementById('a').value // this works
$('#a').val() // as does this
.get
without arguments returns an array. You can pass in 0
to get the first element.
Use
alert($('#a').get(0).value);
get Retrieve the DOM elements matched by the jQuery object.
Try http://jsfiddle.net/2924C/8/
精彩评论