本文介绍了是否有一个jQuery自动完成插件,会强制项目的选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
还有的 的,但它不强制选择一个项目。我需要这样的事情,但它有强制一个项目被选中,然后才能提交。
There's autocomplete, but it doesn't force the selection of an item. I need something like this but it has to force an item to be selected before you can "submit".
是否存在?
推荐答案
这是我与.blur溶液(而且我用的名称| ID对)
This is my solution with .blur (moreover I use name|ID pairs)
jQuery("#username").autocomplete(
"/yii_app/stock/suggestUser",
{
'mustMatch':true,
'multiple':false,
'formatItem':function(result, i, num, term) {
return '<small>'+result[1]+'</small> '+ result[0];
}
}
).result(
function(event,item) {
$("#user_id").val(item[1]);
}
).blur(
function() {
$("#user_id").val('');
$(this).search();
}
);
user_id是一个隐藏的输入字段,用户名是一个文本输入框
AJAX结果使用以下格式:
user1name | user1id \\ n
user2name | user2id \\ n
user_id is a hidden input field, username is an text input fieldajax result uses the following format:user1name|user1id\nuser2name|user2id\n
这篇关于是否有一个jQuery自动完成插件,会强制项目的选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!