jQuery 自动完成 - 仅在输入特殊字符时才需要启动
我相信你们已经看过这个优秀的插件:
http://code.drewwilson.com /entry/autosuggest-jquery-plugin
我检查了一下,找不到仅在键入特定字符时启动自动建议插件的选项。在本例中,我需要它是 at 符号“@”。
我看到它可以选择设置最小字符数: minChars: number (默认为 1)
但是,我需要在键入 @ 符号之前不显示下拉列表。
仅供参考,这是 jquery.autoSuggest.js 中的选项,
var defaults = {
asHtmlID: false,
startText: "Enter Name Here",
emptyText: "No Results Found",
preFill: {},
limitText: "No More Selections Are Allowed",
selectedItemProp: "value", //name of object property
selectedValuesProp: "value", //name of object property
searchObjProps: "value", //comma separated list of object property names
queryParam: "q",
retrieveLimit: false, //number for 'limit' param on ajax request
extraParams: "",
matchCase: false,
minChars: 1,
keyDelay: 400,
resultsHighlight: true,
neverSubmit: false,
selectionLimit: false,
showResultList: true,
start: function(){},
selectionClick: function(elem){},
selectionAdded: function(elem){},
selectionRemoved: function(elem){ elem.remove(); },
formatList: false, //callback function
beforeRetrieve: function(string){ return string; },
retrieveComplete: function(data){ return data; },
resultClick: function(data){},
resultsComplete: function(){}
};
var opts = $
谢谢!
I'm sure you guys have seen this excellent plugin:
http://code.drewwilson.com/entry/autosuggest-jquery-plugin
I checked it out and could not find an option to initiate the autosuggest plugin only when a specific character is typed. In this case I need it to be the at sign '@'.
I see it has the option to set a minimum number of characters:
minChars: number (1 by default)
However, I need for the dropdown to NOT show until the @ sign is typed.
FYI, here are the options in jquery.autoSuggest.js
var defaults = {
asHtmlID: false,
startText: "Enter Name Here",
emptyText: "No Results Found",
preFill: {},
limitText: "No More Selections Are Allowed",
selectedItemProp: "value", //name of object property
selectedValuesProp: "value", //name of object property
searchObjProps: "value", //comma separated list of object property names
queryParam: "q",
retrieveLimit: false, //number for 'limit' param on ajax request
extraParams: "",
matchCase: false,
minChars: 1,
keyDelay: 400,
resultsHighlight: true,
neverSubmit: false,
selectionLimit: false,
showResultList: true,
start: function(){},
selectionClick: function(elem){},
selectionAdded: function(elem){},
selectionRemoved: function(elem){ elem.remove(); },
formatList: false, //callback function
beforeRetrieve: function(string){ return string; },
retrieveComplete: function(data){ return data; },
resultClick: function(data){},
resultsComplete: function(){}
};
var opts = $
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您可以使用
beforeRetrieve
:来自文档:
beforeRetrieve: 回调函数 - 在发出 AJAX 请求之前或在搜索本地对象之前运行的自定义函数。这用于在处理搜索字符串之前对其进行修改。因此,如果用户在 AutoSuggest 框中输入“jim”,您可以调用此函数在其查询前添加“guy_”。进行最终查询=“guy_jim”。搜索查询被传递到该函数中。示例: beforeRetrieve: function(string){ return string; }
I think you can play with
beforeRetrieve
:From the doc:
beforeRetrieve: callback function - Custom function that is run right before the AJAX request is made, or before the local objected is searched. This is used to modify the search string before it is processed. So if a user entered "jim" into the AutoSuggest box, you can call this function to prepend their query with "guy_". Making the final query = "guy_jim". The search query is passed into this function. Example: beforeRetrieve: function(string){ return string; }
我以前从未使用过此控件,但看起来您需要查看
jquery.autoSuggest.js
文件(未缩小)。查看此案例陈述。我认为您需要将default:
大小写更改为case x:
其中x
是您要使用的密钥的 ascii 代码触发自动完成。可能更像这样
I have never used this control before, but it looks like you're going to want to look into the
jquery.autoSuggest.js
file (non minified). Check out this case statement. I think you'll need to change thedefault:
case tocase x:
wherex
is the ascii code for the key you want to use to trigger the autocomplete.Could be more like this