开发者

Simple jQuery: Why does this not work?

开发者 https://www.devze.com 2023-03-19 18:30 出处:网络
T开发者_开发技巧he value is always undefined (Chrome 12.0.742.112). The .get() does return an HTML input object but accessing value is undefined.

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/

0

精彩评论

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