简体   繁体   English

如何不允许使用逗号和Tab jQuery自动建议来生成选择?

[英]How not to allow generating selection using comma and tab jquery autosuggest?

Hey guys, I'm using JQuery's autosuggest and it's working great, just one question. 大家好,我使用的是JQuery的自动提示功能,而且效果很好,只是一个问题。 If a user types something and it's not there he could simply click comma or tab and he adds the value. 如果用户键入了某项内容,但没有输入,则只需单击逗号或制表符,然后添加值。 My question is, how can I disable that and allow him only to select the results and nothing else? 我的问题是,如何禁用该功能,只允许他选择结果,而没有其他选择?

<script type="text/javascript">

$(function(){
    var data = {items: [
    <?php 

    $mysql=mysql_connect('localhost','samaniac','ghobisdabomb');
    mysql_select_db('jmtdy');
    $result=mysql_query("select * from users where username='".$_SESSION['username']."'") or die(mysql_error());
    $dbarray=mysql_fetch_assoc($result);
    $result2=mysql_query("select * from friendship where userid='".$dbarray['id']."'");
    while($dbarray2=mysql_fetch_assoc($result2)){
        $result3=mysql_query("select * from users where id='".$dbarray2['friendid']."'");
        $dbarray3=mysql_fetch_assoc($result3);


        echo '{value: "'.$dbarray3['id'].'", name: "'.$dbarray3['username'].'"},';
        }
        ?>
]};
$("#suggestedfriend").autoSuggest(data.items, {selectedItemProp: "name", searchObjProps: "name", asHtmlID: "clippedon", startText: "Enter Username",retrieveLimit:5});
});







</script>

And yes I know I'm using php in my jquery script, but it's working just the way I want it to. 是的,我知道我在jquery脚本中使用了php,但是它的工作方式与我想要的一样。

What you need is an combo plugin and not autosuggest. 您需要的是一个组合插件,而不是自动建议。 The autosuggest per definition only suggests and not forces, the work to customise jquery autosuggest has largest than you use a combo plugin 每个定义的autosuggest仅建议而非强制,自定义jquery autosuggest的工作比使用组合插件要多

try this http://code.google.com/p/sexy-combo/ 试试这个http://code.google.com/p/sexy-combo/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM