问题描述
我正在尝试根据输入的邮政编码使用googlemap动态更新div.如果用户远离输入框(id为ZipCode),则其工作正常,但如果按Enter键,则不会模糊该字段.我在使用onkeyup时遇到了一些变化,但是一个事件调用了另一个事件,这很混乱.如果任何一个事件发生,是否有可能启动该功能.
I am trying to update a div dynmically with a googlemap based on a zip code being entered. Its working fine if the user tabs away from the input box (id ZipCode) but if they press enter it doesn't blur the field. I have got a variation on this working with onkeyup, but one event calls the other and its a mess. Is it possible to kick the function off if either event occurs.
$(document).ready(function() {
$("#ZipCode").blur(function() {
$("#dynamic").load('googlemap.php', {zipcode: $('#ZipCode').val(), maxdistance: $("input[name='MaxDistance']:checked").val() },
function() {
});
});
}) ;
感谢任何指针.
推荐答案
您可以执行以下操作:
$(document).ready(function() {
$("#ZipCode").bind('blur keyup',function(e) {
if (e.type === 'blur' || e.keyCode === 13)
// do your stuff here
});
});
语法:event.keyCode
返回值:一个数字,代表Unicode字符代码或Unicode密钥代码
Syntax: event.keyCode
Return Value: A Number, representing either a Unicode character code or the Unicode key code
这篇关于jQuery模糊和Enter键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!