0
我是jquery &的新手,並且正在嘗試學習它們。按照我的預期,以下方法可行,除非有人輸入東西並點擊ENTER。然後文本框變爲空白。我如何壓制這一點?我希望它能觸發現有事件之一 - 選擇或更改。謝謝,無法捕捉或禁止自動完成中的ENTER按鈕
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Demo</title>
<style>
a.test { font-weight: bold; }
</style>
</head>
<body>
<link rel="stylesheet" type="text/css" href="css/ui-lightness/jquery-ui-1.8.18.custom.css">
<link rel="stylesheet" type="text/css" href="css/autocomplete.css">
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.18.custom.min.js"></script>
<script>
$(document).ready(function(){
//attach autocomplete
$("#suggest4").autocomplete({
//define callback to format results
source: function(req, add){
//pass request to server
$.getJSON("friends.php?callback=?", req, function(data) {
//create array for response objects
var suggestions = [];
//process response
$.each(data, function(i, val){
suggestions.push(val.name);
});
//pass array to callback
add(suggestions);
});
},
//define select handler
select: function(e, ui) {
$("#spill").html("change "+ui.item.value+" "+e.type);
},
//define select handler
change: function(e) {
$("#spill").html("change "+$(this).val()+e.type);
}
});
});
</script>
<div id="content">
<form>
<p>
<label>Multiple Birds (local):</label>
<input type="text" id="suggest4"></input>
</p>
</form>
</div>
<div id="spill">
</div>
</body>
</html>