Get "change" to work in IE9
I cant get .change() to work with an input in Internet Explorer 9. It works in all other browsers (that I've tried) but not IE 9.
<html>
<head>
开发者_如何学Python <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function() {
$('.myInput').change(function () {
alert("hi");
});
});
</script>
<input class="myInput" />
</body>
</html>
Any ideas?
Just tell IE that it's textbox by adding proper attribute:
<input class="myInput" type="text" />
Edit: while still better practice to specify the type, that wasn't the problem, it works fine in IE9 for me, so like Jon asked: what you mean by "not working"?
It works when I test it: http://jsfiddle.net/Guffa/WUEXD/
I would recommend you to have a doctype on the page, which would be the XHTML doctype as you are using XHTML in your code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
To avoid problems with picky browsers, put the input in a form, and set the type
attribute:
<form>
<input type="text" class="myInput" />
</form>
Sorry guys. Just as you said it DOES work. The problem was that I also had a validate script on the input with a regualar expression that didn’t work in IE9 (but in IE8). Big thank you though…
Use keypress instead of change.
$('.myInput').keypress(function () {
alert("hi");
});
精彩评论