JqueryUI自动完成功能可防止在每次按键时调用 [英] JqueryUI Autocomplete prevent call on every keypress

查看:64
本文介绍了JqueryUI自动完成功能可防止在每次按键时调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JqueryUI自动完成功能,我想做的是防止JqueryUI自动完成功能在每次按键时进行调用.一切都以完美的方式进行.我已经将文本字段与自动完成功能绑定在一起,但是每按一次它都会拨打电话.如何防止拨打特定按键?例如,我想防止按箭头键.这是我在Coffee中的代码.

I am working with JqueryUI Autocomplete, what I want to do is to prevent JqueryUI autocomplete to make call on every keypress. Everything is working in perfect manner. I have bind the textfield with autocomplete but on every key press it make the call. How can i prevent call on specific keys ? e.g i want to prevent the call on arrow keys. Here is my code in Coffee.

$("#location-search").autocomplete
        source: (request, response) ->
          if request.term.length < 1
            $(".pen-dropdown").hide() 
          else
            $.ajax
              url: "http://ws.geonames.org/searchJSON?country=US&lang=en&username=awais545"
              dataType: "jsonp"
              data:
                maxRows: 10
                name_startsWith: request.term

              success: (data) ->
                rows = new Array()
                data = data.geonames
                i = 0

                while i < data.length
                  rows[i] =
                  value:        data[i].name
                  country_code: data[i].adminCode1
                  i++
                rows

                $("#location-search").parent().find(".pen-dropdown ul").html("")

                if $("#location-search").parent().find(".header-loaction").length > 0
                  $("#location-search").parent().find(".pen-dropdown ul").append("<li><a href='#'> All Area </a></li>")

                for row, i in rows
                  $("#location-search").parent().find(".pen-dropdown ul").append("<li><a href='#'> #{row['value']}, #{row['country_code']} </a></li>")
                  window.dropdownli = $(".pen-dropdown li")
                  window.dropdownliSelected = undefined

                for li in $("#location-search").parent().find(".pen-dropdown ul li")
                  $(li).click(setLocationTitle)

                $("#location-search").parent().find(".pen-dropdown").show()

谢谢

推荐答案

我遇到了类似的问题.我使用自动完成功能中的事件" search(event,ui)"修复了该问题.

I had similar issue. I fixed it using event "search( event, ui )" in autocomplete.

 $("#autocompleteText").autocomplete({
            search: function (event, ui) {
           /*keyCode will "undefined" if user presses any function keys*/
                if(event.keyCode)
                { event.preventDefault(); }
            },
            autoFocus:false,
            minLength:3,
            source: function (request, response) {
                //make remote call for result.                   
            }

        });

这篇关于JqueryUI自动完成功能可防止在每次按键时调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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