【发布时间】:2017-08-30 22:02:42
【问题描述】:
我正在使用 JqueryUI 自动完成功能,我想做的是防止 JqueryUI 自动完成功能在每次按键时都进行调用。一切都以完美的方式工作。我已将文本字段与自动完成绑定,但每次按键时都会拨打电话。如何防止调用特定键?例如,我想阻止对箭头键的调用。这是我在 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()
谢谢
【问题讨论】:
-
但我在任何地方都没有事件对象,我怎样才能让按键与自动完成绑定?
-
我不熟悉Coffeescript,但在你的自动完成功能中你应该能够绑定
stopPropagation()处理程序,就像这样:$("#location-search").bind('autocompletechange', function(event, ui) { event.stopPropagation(); });
标签: jquery jquery-ui autocomplete