非常简单 直接代码
(function($) {
$.fn.watch = function(callback) {
return this.each(function() {
//缓存以前的值
$.data(this, 'originVal', $(this).val()); //event
$(this).on('keyup paste', function() {
var originVal = $(this, 'originVal');
var currentVal = $(this).val(); if (originVal !== currentVal) {
$.data(this, 'originVal', $(this).val());
callback(currentVal);
}
});
});
}
})(jQuery);
$(document).ready(function() {标签:jquery,function,originVal,val,watch,currentVal,输入框,var,input From: https://blog.51cto.com/u_14877002/5765894
$("#barcode").watch(function(value) {
//...
});
});