并非所有浏览器都支持相同的复制/粘贴功能。以下是哪个浏览器支持哪些功能的图表:
http://www.quirksmode.org/dom/events/cutcopypaste.html
如果浏览器支持捕获复制/粘贴事件,jQuery 应该可以正常工作。我建议测试您的每个目标浏览器。
另一种方法是使用 jQuery 的“数据”属性来检测输入字段是否已更改。这是一篇带有示例代码的文章:
http://www.mydogboris.com/2009/10/using-jquery-data-feature-to-detect-form-changes/
来自文章:
var formChanged = false;
$(document).ready(function() {
$('#my_form input[type=text].editable, #my_form textarea.editable').each(function (i) {
$(this).data('initial_value', $(this).val());
});
$('#my_form input[type=text].editable, #my_form textarea.editable').keyup(function() {
if ($(this).val() != $(this).data('initial_value')) {
handleFormChanged();
}
});
$('#my_form .editable').bind('change paste', function() {
handleFormChanged();
});
$('.navigation_link').bind("click", function () {
return confirmNavigation();
});
});
function handleFormChanged() {
$('#save_or_update').attr("disabled", false);
formChanged = true;
}
function confirmNavigation() {
if (formChanged) {
return confirm('Are you sure? Your changes will be lost!');
} else {
return true;
}
}