Leo

软件编程技术

导航

MVC中使用Jquery.AutoComplete函数使用实例(原创)

Posted on 2015-03-09 00:28  Leo(binbin)  阅读(133)  评论(0编辑  收藏  举报

———————————————前端如下—————————————————————

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="Scripts/jquery-1.7.1.js"></script>
<link href="jquery.autocomplete.css" rel="stylesheet" />
<script src="jquery.autocomplete.js"></script>
<script type="text/javascript">
var emails = [
{ name: "Leo1", link: "http://www.baidu.com" },
{ name: "Leo2", link: "http://www.baidu.com" },
];

$(function () {
$('#keyword').autocomplete(emails, {
max: 12, //列表里的条目数
minChars: 0, //自动完成激活之前填入的最小字符
width: 400, //提示的宽度,溢出隐藏
scrollHeight: 300, //提示的高度,溢出显示滚动条
matchContains: true, //包含匹配,就是data参数里的数据,是否只要包含文本框里的数据就显示
autoFill: false, //自动填充
formatItem: function (row, i, max) {
return i + '/' + max + ':"' + row.name + '"[' + row.link + ']';
},
formatMatch: function (row, i, max) {
return row.name + row.link;
},
formatResult: function (row) {
return row.name;
}
}).result(function (event, row, formatted) {
alert(row.link);
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="keyword" />
<input id="getValue" value="GetValue" type="button" />
</div>
</form>
</body>
</html>

 

———————————————后端如下—————————————————————

public ContentResult GetItems(参数1) 

  //查询数据集合代码块...
  string strResult = "{text:'Link A', url:'/page1'}\n {text:'Link B', url: '/page2'} ";  //数据格式化
  return Content(strResult); 

点击这里给我发消息