jQuery自动完成在下拉列表中显示提示文本
标记器: 当用户关注输入时,显示提示“键入搜索词”。使用jQueryUI的自动完成功能可以做到这一点吗jQuery自动完成在下拉列表中显示提示文本,jquery,jquery-ui,jquery-ui-autocomplete,Jquery,Jquery Ui,Jquery Ui Autocomplete,标记器: 当用户关注输入时,显示提示“键入搜索词”。使用jQueryUI的自动完成功能可以做到这一点吗 我正在使用一个远程数据源,但我想可能会分配一个长度为1的临时数据源([“键入搜索词”,下称“]),以便在启动搜索之前自动完成?这就是您要寻找的:更新演示*旧版=>*工作演示 我想你要找的是: 希望它适合你的事业:) 脚本 <script type='text/javascript' src="https://raw.github.com/loopj/jquery-tokeninpu
我正在使用一个远程数据源,但我想可能会分配一个长度为1的临时数据源([“键入搜索词”,下称“]),以便在启动搜索之前自动完成?这就是您要寻找的:更新演示*旧版=>*工作演示 我想你要找的是: 希望它适合你的事业
:)
脚本
<script type='text/javascript' src="https://raw.github.com/loopj/jquery-tokeninput/master/src/jquery.tokeninput.js"></script>
<link rel="stylesheet" type="text/css" href="http://loopj.com/jquery-tokeninput/styles/token-input.css">
<link rel="stylesheet" type="text/css" href="http://loopj.com/jquery-tokeninput/styles/token-input-facebook.css">
代码
$(document).ready(function() {
$("#demo-input-local-custom-formatters").tokenInput([{
"first_name": "Tats_innit",
"last_name": "Godfrey",
"email": "Tats_innit@mit.whatwhatwuthulk.edu",
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
},
{
"first_name": "Andre",
"last_name": "Jackson",
"email": "andre.jackson@yahoo.com",
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
},
{
"first_name": "Andre",
"last_name": "Jolly",
"email": "andre.jolly@uol.com.br",
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
},
{
"first_name": "Andre",
"last_name": "Henderson",
"email": "andre.henderson@globo.com",
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
}
], {
propertyToSearch: "first_name",
resultsFormatter: function(item){ return "<li>" + "<img src='" + item.url + "' title='" + item.first_name + " " + item.last_name + "' height='25px' width='25px' />" + "<div style='display: inline-block; padding-left: 10px;'><div class='full_name'>" + item.first_name + " " + item.last_name + "</div><div class='email'>" + item.email + "</div></div></li>" },
tokenFormatter: function(item) { return "<li><p>" + item.first_name + " <b style='color: red'>" + item.last_name + "</b></p></li>" },
});
});
$(文档).ready(函数(){
$(“#演示输入本地自定义格式化程序”).tokenInput([{
“名字”:“Tats_innit”,
“姓”:“戈弗雷”,
“电子邮件”:“Tats”_innit@mit.whatwhatwuthulk.edu",
“url”:”https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
},
{
“名字”:“安德烈”,
“姓氏”:“杰克逊”,
“电子邮件”:“安德烈。jackson@yahoo.com",
“url”:”https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
},
{
“名字”:“安德烈”,
“姓氏”:“Jolly”,
“电子邮件”:“安德烈。jolly@uol.com.br",
“url”:”https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
},
{
“名字”:“安德烈”,
“姓”:“亨德森”,
“电子邮件”:“安德烈。henderson@globo.com",
“url”:”https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
}
], {
propertyToSearch:“名字”,
结果格式化程序:函数(项){return“”+“”+“”+item.first\u name+“”+item.last\u name+“”+item.email+“ ”},
tokenFormatter:函数(项){return“”+item.first\u name+“”+item.last\u name+” “},
});
});
工作图像
$(document).ready(function() {
$("#demo-input-local-custom-formatters").tokenInput([{
"first_name": "Tats_innit",
"last_name": "Godfrey",
"email": "Tats_innit@mit.whatwhatwuthulk.edu",
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
},
{
"first_name": "Andre",
"last_name": "Jackson",
"email": "andre.jackson@yahoo.com",
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
},
{
"first_name": "Andre",
"last_name": "Jolly",
"email": "andre.jolly@uol.com.br",
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
},
{
"first_name": "Andre",
"last_name": "Henderson",
"email": "andre.henderson@globo.com",
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
}
], {
propertyToSearch: "first_name",
resultsFormatter: function(item){ return "<li>" + "<img src='" + item.url + "' title='" + item.first_name + " " + item.last_name + "' height='25px' width='25px' />" + "<div style='display: inline-block; padding-left: 10px;'><div class='full_name'>" + item.first_name + " " + item.last_name + "</div><div class='email'>" + item.email + "</div></div></li>" },
tokenFormatter: function(item) { return "<li><p>" + item.first_name + " <b style='color: red'>" + item.last_name + "</b></p></li>" },
});
});
顺便说一句,我不是戈弗雷
这就是您要寻找的:更新演示*旧版=>*工作演示 我想你要找的是: 希望它适合你的事业
:)
脚本
<script type='text/javascript' src="https://raw.github.com/loopj/jquery-tokeninput/master/src/jquery.tokeninput.js"></script>
<link rel="stylesheet" type="text/css" href="http://loopj.com/jquery-tokeninput/styles/token-input.css">
<link rel="stylesheet" type="text/css" href="http://loopj.com/jquery-tokeninput/styles/token-input-facebook.css">
代码
$(document).ready(function() {
$("#demo-input-local-custom-formatters").tokenInput([{
"first_name": "Tats_innit",
"last_name": "Godfrey",
"email": "Tats_innit@mit.whatwhatwuthulk.edu",
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
},
{
"first_name": "Andre",
"last_name": "Jackson",
"email": "andre.jackson@yahoo.com",
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
},
{
"first_name": "Andre",
"last_name": "Jolly",
"email": "andre.jolly@uol.com.br",
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
},
{
"first_name": "Andre",
"last_name": "Henderson",
"email": "andre.henderson@globo.com",
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
}
], {
propertyToSearch: "first_name",
resultsFormatter: function(item){ return "<li>" + "<img src='" + item.url + "' title='" + item.first_name + " " + item.last_name + "' height='25px' width='25px' />" + "<div style='display: inline-block; padding-left: 10px;'><div class='full_name'>" + item.first_name + " " + item.last_name + "</div><div class='email'>" + item.email + "</div></div></li>" },
tokenFormatter: function(item) { return "<li><p>" + item.first_name + " <b style='color: red'>" + item.last_name + "</b></p></li>" },
});
});
$(文档).ready(函数(){
$(“#演示输入本地自定义格式化程序”).tokenInput([{
“名字”:“Tats_innit”,
“姓”:“戈弗雷”,
“电子邮件”:“Tats”_innit@mit.whatwhatwuthulk.edu",
“url”:”https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
},
{
“名字”:“安德烈”,
“姓氏”:“杰克逊”,
“电子邮件”:“安德烈。jackson@yahoo.com",
“url”:”https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
},
{
“名字”:“安德烈”,
“姓氏”:“Jolly”,
“电子邮件”:“安德烈。jolly@uol.com.br",
“url”:”https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
},
{
“名字”:“安德烈”,
“姓”:“亨德森”,
“电子邮件”:“安德烈。henderson@globo.com",
“url”:”https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
}
], {
propertyToSearch:“名字”,
结果格式化程序:函数(项){return“”+“”+“”+item.first\u name+“”+item.last\u name+“”+item.email+“ ”},
tokenFormatter:函数(项){return“”+item.first\u name+“”+item.last\u name+” “},
});
});
工作图像
$(document).ready(function() {
$("#demo-input-local-custom-formatters").tokenInput([{
"first_name": "Tats_innit",
"last_name": "Godfrey",
"email": "Tats_innit@mit.whatwhatwuthulk.edu",
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
},
{
"first_name": "Andre",
"last_name": "Jackson",
"email": "andre.jackson@yahoo.com",
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
},
{
"first_name": "Andre",
"last_name": "Jolly",
"email": "andre.jolly@uol.com.br",
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
},
{
"first_name": "Andre",
"last_name": "Henderson",
"email": "andre.henderson@globo.com",
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
}
], {
propertyToSearch: "first_name",
resultsFormatter: function(item){ return "<li>" + "<img src='" + item.url + "' title='" + item.first_name + " " + item.last_name + "' height='25px' width='25px' />" + "<div style='display: inline-block; padding-left: 10px;'><div class='full_name'>" + item.first_name + " " + item.last_name + "</div><div class='email'>" + item.email + "</div></div></li>" },
tokenFormatter: function(item) { return "<li><p>" + item.first_name + " <b style='color: red'>" + item.last_name + "</b></p></li>" },
});
});
顺便说一句,我不是戈弗雷
这里需要做的是更新
源
参数,这样您就可以自己发出AJAX请求了。当您等待AJAX请求返回时,您将向小部件传递一个“加载”项(如您在问题中所建议的):
select
和focus
事件处理程序用于防止单击或聚焦“加载”项。不幸的是,当您单击加载项时,加载项会消失,但如果这是一个大问题,则可以很容易地修复它
示例:这里需要做的是更新
源
参数,以便您可以自己发出AJAX请求。当您等待AJAX请求返回时,您将向小部件传递一个“加载”项(如您在问题中所建议的):
select
和focus
事件处理程序用于防止单击或聚焦“加载”项。不幸的是,当您单击加载项时,加载项会消失,但如果这是一个大问题,则可以很容易地修复它
示例:我认为这不是我想要的。我希望当用户单击输入框开始时,下拉列表显示提示(“输入搜索词…”)typing@TylerDeWitt嗨,老兄,更新了我的答案,希望它能帮你,老兄<代码>:)我想这不是我想要的。我希望当用户单击输入框开始时,下拉列表显示提示(“输入搜索词…”)typing@TylerDeWitt嗨,老兄,更新了我的答案,希望它能帮你,老兄<代码>:)