自动完成的jQuery删除'-'之后的所有内容 [英] Autocomplete Jquery remove everything after ' - '

查看:84
本文介绍了自动完成的jQuery删除'-'之后的所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用简单的JQUERY自动完成功能来显示某些记录的可能重复项,例如在用户填写文本字段时显示姓名或地址.

I use a simply JQUERY Autocomplete to show possibles duplicates for certains records, like Name or address when user fill in a textfield.

此处代码

<script type="text/javascript">
                $(function() {
                    var availableTags = <?php include('ajax/ajax_show.php'); ?>;
                    $("#name_value").autocomplete({
                        source: availableTags,
                        autoFocus:true
                    });
                });
            </script>

下面的文本是显示结果.

Below text filed are displayes results.

Name[____________________]
 Paul - 121.456.789-00
 Robert - 122.456.789-00
 Cid - 123.456.789-00

如何删除-之后的所有内容(空格连字符空间)及其后的所有内容,并且在文本字段中仅具有Paul,Robert或Cid之类的名称?

How to remove all after - (space hyphen space) and everything after it and have in textfield only name like Paul, Robert or Cid?

推荐答案

要简单地删除数字并在输入框中显示名称,可以使用substrindexOf(或者可以使用正则表达式和replace(如果愿意).像这样:

To simply remove the numbers and show the name in an input box, you can use substr and indexOf (or you can work with regular expressions and replace if you prefer). Like this:

$( "#name_value" ).autocomplete({
    select: function( event, ui ) {
        $('#myInputBox').text(ui.item.value.substr(0, ui.item.value.indexOf(" - ")));
    }
});    

您可能要在此处

You might want to look up these two functions here and here to see how this works.

这篇关于自动完成的jQuery删除'-'之后的所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆