87,990
社区成员
发帖
与我相关
我的任务
分享
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>测试页面</title>
<script src="js/jquery-1.3.2.js" type="text/javascript"></script>
<script type='text/javascript' src='js/jquery.autocomplete.js'></script>
<script type='text/javascript' src='js/localdata.js'></script>
<link rel="stylesheet" type="text/css" href="css/main.css" />
<link rel="stylesheet" type="text/css" href="css/jquery.autocomplete.css" />
<link rel="stylesheet" type="text/css" href="css/thickbox.css" />
<script type="text/javascript">
function add() {
var tr = $("#table1 tr").eq(0).clone();
tr.appendTo("#table1");
}
$().ready(function(){
//1 example
$("#suggest1").autocomplete(cities);
//2 example
var emails = [
{ name: "Peter Pan", to: "peter@pan.de" },
{ name: "Molly", to: "molly@yahoo.com" },
{ name: "Forneria Marconi", to: "live@japan.jp" },
{ name: "Master <em>Sync</em>", to: "205bw@samsung.com" },
{ name: "Dr. <strong>Tech</strong> de Log", to: "g15@logitech.com" },
{ name: "Don Corleone", to: "don@vegas.com" },
{ name: "Mc Chick", to: "info@donalds.org" },
{ name: "Donnie Darko", to: "dd@timeshift.info" },
{ name: "Quake The Net", to: "webmaster@quakenet.org" },
{ name: "Dr. Write", to: "write@writable.com" }];
$("#autocomplete").autocomplete(emails, {
minChars: 0,
max:15,
width: 200,
autoFill: false,
scroll: false,
scrollHeight: 500,
formatItem: function(data, i, total) {
return data.name+data.to
},
formatMatch: function(data, i, total) {
return data.name;
},
formatResult: function(data, value) {
return data.name;
}
}).result(function(event, data, formatted) { //回调
// alert(data.to);
$("#twoColum_abbr").html(data.to);
});
//3 example
$("#autocom").autocomplete("data.aspx", {
minChars: 0,
max:10,
width: 200,
autoFill: false,
scroll: false,
scrollHeight: 500,
//需要把data转换成json数据格式
parse: function(data) {
return $.map(eval(data), function(row) {
return {
data: row,
value: row.name,
result: row.name + " <" + row.to + ">"
}
});
},
formatItem: function(data, i, total) {
return data.name+data.to
},
formatMatch: function(data, i, total) {
return data.name;
},
formatResult: function(data, value) {
return data.name;
}
}).result(function(event, data, formatted) { //回调
// alert(data.to);
$("#content").html(data.to);
});
})
</script>
</head>
<body>
<form id="form1" runat="server">
自动完成字符串数组:
<input type="text" id="suggest1" />
<br/>
自动完成对象数组:
<input type="text" id="autocomplete" />
<div id="twoColum_abbr"></div>
<br/>
数据库中提出:
<table id="table1">
<tr>
<td><input type="text" id="autocom" /></td>
</tr>
<tr>
<td><a href="#" onclick="add()">add</a></td>
</tr>
</table>
<div id="content"></div>
</form>
</body>
</html>