jQuery v 1.7.1
Chrome v 18.0.1025.162
我有一个附加到下拉菜单的jquery点击事件处理程序。在FF / Safari中,事件处理程序在点击后立即触发,但我在Chrome中观察到奇怪的行为:
可替换地,
$("#dropdown-id").detectRealTimeChange(function(){ $("#some-div").html("html content"); ); /** * Detect a change to an input without requiring the input to lose focus */ jQuery.fn.detectRealTimeChange = function(callback){ var oldValue = $(this).val(); var didRecordChange = false; $(this).keyup(function(){ var newValue = $(this).val(); if(oldValue != newValue){ if(!didRecordChange){ changeCount = changeCount + 1; didRecordChange = true; } } else{ if(didRecordChange){ changeCount = changeCount - 1; didRecordChange = false; } } if(typeof callback == 'function'){ callback.call(this); } }); $(this).click(function(){ var newValue = $(this).val(); if(oldValue != newValue){ if(!didRecordChange){ changeCount = changeCount + 1; didRecordChange = true; } } else{ if(didRecordChange){ changeCount = changeCount - 1; didRecordChange = false; } } if(typeof callback == 'function'){ callback.call(this); } });