据说没有定义onkeyup方法,但是我的ide会自动推荐这个方法.当我在chrome dev工具中查看错误时,我得到错误Uncaught TypeError:Object [object Object]没有方法'onkeyup'.我正在使用最新版本的jQuery.这是我的代码:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
var str = document.getElementById('txt1').value;
$.post("addName.php", {q: str});
});
$("input").onkeyup(function(){
var str = document.getElementById('txt1').value;
$.post("gethint.php", {q: str});
});
});
</script>
</head>
<body>
<h3>Start typing a name in the input field below:</h3>
<form action="">
First name: <input type="text" id="txt1"/>
</form>
<p>Suggestions: <span id="txtHint"></span></p>
<button> Add Name</button>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
the*_*dox 16
$("input").on('keyup', function(){
var str = document.getElementById('txt1').value;
$.post("gethint.php", {q: str});
});
Run Code Online (Sandbox Code Playgroud)
要么
$("input").keyup( function(){
var str = document.getElementById('txt1').value;
$.post("gethint.php", {q: str});
});
Run Code Online (Sandbox Code Playgroud)
jQuery没有方法名称 onkeyup
| 归档时间: |
|
| 查看次数: |
19617 次 |
| 最近记录: |