如何取消Jquery中的箭头键
我有这段代码用于 youtube 自动完成建议:
$(function(){
$('#input-field').keyup(function(){
var val = $(this).val();
jQTubeUtil.suggest(val, function(response){
var html = '';
for(s in response.suggestions){
var sug = response.suggestions[s];
html += '<li class="li-class"><a href="#">'+sug+'</a></li>';
}
if (response.suggestions.length)
$('#autocomplete').html(html).show();
else
$('#autocomplete').hide();
});
});
});
如果按下箭头键(键码 40/38),如何停止发出请求? 我知道这与“!”有关。或事件“.not”,但我的努力没有得到回报。
I have this code which is for youtube autocomplete suggestions:
$(function(){
$('#input-field').keyup(function(){
var val = $(this).val();
jQTubeUtil.suggest(val, function(response){
var html = '';
for(s in response.suggestions){
var sug = response.suggestions[s];
html += '<li class="li-class"><a href="#">'+sug+'</a></li>';
}
if (response.suggestions.length)
$('#autocomplete').html(html).show();
else
$('#autocomplete').hide();
});
});
});
How can I STOP a request being made if an arrow key (keycode 40/38) is being pressed?
I know it has something to do with '!' or event '.not' but my efforts did not pay off.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果键位于这些值之间,您可以简单地返回,从而有效地停止函数执行。
You could simply return, effecitvely halting the function execution, if the key is between those values.
添加一个变量:
$('#input-field').keyup(function(){
likee
请注意,您可能需要检查左侧和右侧也可以使用右键,但不要阻止它们,而是取消您对“其余代码”所做的调用:
add an variable in:
$('#input-field').keyup(function(){
likee
Note that you may want to have a check for the left and right keys also, but dont prevent those but cancel out the call you are doing on "the rest of the code":
尝试此操作以取消一系列键:
Try this to cancel a range of keys: