我在旧的autocomplete jquery上工作,我发现了一些代码,它运行良好,但我想添加一个新功能。选择其中一个选择后,应单击“提交”按钮。但我不擅长JQuery。有人帮忙吗?
ASP页面
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ASP AutoComplete</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.autocomplete.pack.js"></script>
<link rel="stylesheet" type="text/css" href="jquery.autocomplete.css" />
<script type="text/javascript">
function test(){
alert("test);
}
//Script Features::: http://docs.jquery.com/Plugins/Autocomplete/autocomplete#url_or_dataoptions
$().ready(function() {
function formatItem(row) {
return row[0] + " (<strong>id: " + row[1] + "</strong>)";
}
function formatResult(row) {
return row[0].replace(/(<.+?>)/gi, '');
}
$("#input").autocomplete("sorgu.asp", {
width: 151,
selectFirst: false,
cacheLength : 0,
minChars: 2
//autoFill: true
});
$("#input").result(function(event, data, formatted) {
if (data)
$(this).parent().next().find("input").val(data[1]);
});
});
</script>
<style type="text/css">
body { font-family: Helvetica; font-size: 12px; color: #000; }
</style>
</head>
<body>
<div>
<form>
<div>
<div style=" font-size: 20px; color: #F00;">Write some Letter:<div/>
<p>
<label><b>Search:</b></label>
<input type="text" id="input" />
<button value="Submit" onClick="test()" id="bt1">Submit</button>
</p>
</div>
</form>
</div>
</body>
</html>
答案 0 :(得分:0)
$(function() {
$("#input").autocomplete({
width: 151,
selectFirst: false,
cacheLength : 0,
minChars: 2,
select: function(event, ui) {
$("#formname").submit(); }
});
});
这将在select上提交您的表单。