onblur函数不调用jquery自动完成

时间:2016-11-22 06:57:58

标签: php jquery

我正在使用jQuery自动完成功能,我已经完成了选择事件,在选择结果即将到来之后onblur我也想要触发相同的事件,但它不适用于onblur这是我的代码请帮助我解决,对于选择事件,我选择它是什么工作和功能调用,同样的事情不能处理模糊,任何想法?

代码:

<!--Function for Auto Search------>
 <link href="https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet">
      <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
      <script src="https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<!--<script src="<?php echo CUR_URL;?>new_template/assets/js-auto/jquery-ui.js"></script>-->
<script>
$( function() 
{

    function log( message ) 
    {
      $( "<div>" ).text( message ).prependTo("#log");
      $( "#log" ).scrollTop(0);
    }

    function myfun( event, ui ) 
        {
            $("#log").html('');  
            log( ui.item ?"Selected: " + ui.item.value + " ID is " + ui.item.id :"Nothing selected, input was " + this.value );

            var ids = ui.item.id;
            var values = ui.item.value;
            search_id_arr = ids.split("-");
            var formdata =  ({
                search_id   : search_id_arr['0'],
                search_name   : search_id_arr['1'],
                                speciality_name   : values
            });
            $.ajax({
                url: "<?php echo CUR_URL; ?>new_template/ajax_code.php?data=setSearch_id",
                type: 'post',
                data: formdata,
                success: function (data) 
                { 
                    if(data !='')
                    {
                        if(search_id_arr['1'] == 'specilization' || search_id_arr['1'] =='service')
                        {
                            window.location.href="<?php echo CUR_URL; ?>search_detail";
                        }
                        else if(search_id_arr['1'] == 'doctor' || search_id_arr['1'] == 'clinic')
                        {
                            window.location.href="<?php echo CUR_URL; ?>profile_detail";
                        }
                    }
                }
            });
        }

    $("#search_key").autocomplete({
        source: "<?php echo CUR_URL ;?>new_template/ajax_code.php",
        autoFocus: true,
        minLength: 2,
        select: myfun,
        blur:myfun
    });
});
</script>

1 个答案:

答案 0 :(得分:0)

模糊事件在jquery自动完成中不可用。
它仅支持以下事件。

  • 变化
  • 靠近
  • 创建
  • 焦点
  • 响应
  • 搜索
  • 选择

参考:https://api.jqueryui.com/autocomplete/

因此,您可能需要单独附加模糊事件。 示例 $("#select option").blur(function(){ myfun(); });

相关问题