//show city/state on input maxlength
$("input#billZipCode").live("keyup", function( event ){
if(this.value.length == this.getAttribute('maxlength')) {
if(!$(this).data('triggered')) {
// set the 'triggered' data attribute to true
$(this).data('triggered', true);
if ($(this).valid() == true ) { zipLookup(this, "USA"); }
}
} else {
$(this).data('triggered', false);
}
});
函数zipLookup
执行ajax调用并填充字段。
当用户输入zipcode时,上述方法有效-但是,如果用户输入zipcode,然后粘贴(CTRL V)新的Zipcode值,则该函数不会再次触发。
发布于 2012-08-28 15:00:05
您可以捕获paste事件:
$(document).on('change keyup paste', '#billZipCode', function(){
// do something
});
jquery使用的onpaste
回调的引用:https://developer.mozilla.org/en-US/docs/DOM/element.onpaste
请注意,正如在the documentation中指定的那样,这在IE8上不起作用:您必须将paste
事件直接附加到元素:
在Internet Explorer8和更低版本中,粘贴和重置事件不会冒泡。此类事件不支持与委托一起使用,但当事件处理程序直接附加到生成事件的元素时,可以使用这些事件。
附注:
on
,而不是live
(已弃用)https://stackoverflow.com/questions/12161976
复制