下面是jquery.autocomplete.min.js的一个简单的例子。
我想问是的怎么动态的跟后台交互,不是写死的,而是从数据库里面得到的。本人小白,最好是能有一个实例。前台后台的都有最好了。谢谢
<script type="text/javascript">
var emails = [
{ name: "Peter Pan", to: "[email protected]" },
{ name: "Molly", to: "[email protected]" },
{ name: "Forneria Marconi", to: "[email protected]" },
{ name: "Master <em>Sync</em>", to: "[email protected]" },
{ name: "Dr. <strong>Tech</strong> de Log", to: "[email protected]" },
{ name: "Don Corleone", to: "[email protected]" },
{ name: "Mc Chick", to: "[email protected]" },
{ name: "Donnie Darko", to: "[email protected]" },
{ name: "Quake The Net", to: "[email protected]" },
{ name: "Dr. Write", to: "[email protected]" },
{ name: "GG Bond", to: "[email protected]" },
{ name: "Zhuzhu Xia", to: "[email protected]" }
];
$(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.to + ']';
},
formatMatch: function(row, i, max) {
return row.name + row.to;
},
formatResult: function(row) {
return row.to;
}
}).result(function(event, row, formatted) {
alert(row.to);
});
});
</script>JavaScriptjquery
我想问是的怎么动态的跟后台交互,不是写死的,而是从数据库里面得到的。本人小白,最好是能有一个实例。前台后台的都有最好了。谢谢
<script type="text/javascript">
var emails = [
{ name: "Peter Pan", to: "[email protected]" },
{ name: "Molly", to: "[email protected]" },
{ name: "Forneria Marconi", to: "[email protected]" },
{ name: "Master <em>Sync</em>", to: "[email protected]" },
{ name: "Dr. <strong>Tech</strong> de Log", to: "[email protected]" },
{ name: "Don Corleone", to: "[email protected]" },
{ name: "Mc Chick", to: "[email protected]" },
{ name: "Donnie Darko", to: "[email protected]" },
{ name: "Quake The Net", to: "[email protected]" },
{ name: "Dr. Write", to: "[email protected]" },
{ name: "GG Bond", to: "[email protected]" },
{ name: "Zhuzhu Xia", to: "[email protected]" }
];
$(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.to + ']';
},
formatMatch: function(row, i, max) {
return row.name + row.to;
},
formatResult: function(row) {
return row.to;
}
}).result(function(event, row, formatted) {
alert(row.to);
});
});
</script>JavaScriptjquery
解决方案 »
- 为什么越来越快???如何解决? 急!!
- 如何设定flexigrid 第一加载数据时,加载指定页数的数据
- UltraWebGrid如何前端綁定?
- 在线等:window.top.mainbodyFrame.leftFrame.treeFrame.location问题
- 求助:打印动态网页中,表格所检索出来的所有内容(包括未显示出的)
- 一个层隐藏与显示的问题,请教............
- iframe能自己调节高度吗?
- 关于一个的问题
- foolfish ---->进来接分
- jquery设置easyui-combobox只读属性
- extjs4一般大点的公司会用这个框架吗
- JQuery easyui Datagrid排序问题
$(function () {
var url = "/RepairIn/InitFailCode";
$.ajax({
type: "POST",
async: false,
url: encodeURI(url),
success: function (data) {
$('#failCode').autocomplete(data, {
max: 10, //列表里的条目数
minChars: 1, //自动完成激活之前填入的最小字符
width: 300, //提示的宽度,溢出隐藏
scrollHeight: 300, //提示的高度,溢出显示滚动条
matchContains: true, //包含匹配,就是data参数里的数据,是否只要包含文本框里的数据就显示
autoFill: false, //自动填充
formatItem: function (row, i, max) {
return i + ':"' + row.Code + '"[' + row.Name + ']';
},
formatMatch: function (row, i, max) {
return row.Code + row.Name;
},
formatResult: function (row) {
return row.Code;
}
}).result(function (event, row, formatted) {
document.getElementById("failName").value = row.Name;
checkSubmit();
});
}
});
});后台返回JSON数组
public ActionResult InitFailCode()
{
List<object> items = new List<object>(); using (DataTable dt = _failCode.SelectFailCode("", "", 1))
{
foreach (DataRow dr in dt.Rows)
{
var item = new { Code = dr["FAILURE_CODE"].ToString().Trim(), Name = dr["FAILURE_NAME"].ToString().Trim() };
items.Add(item);
}
} return Json(items, JsonRequestBehavior.AllowGet);
}
在1楼的代码示命名, ajax url后面拼,或者是用 data:{param:param} 方式进行传递参数