且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

更改contenteditable时触发事件

更新时间:2023-02-13 13:02:09

只需将内容存储到变量中,并检查在blur()事件之后它是否不同.如果不同,请存储新内容.

Just store the contents to a variable and check if it is different after blur() event. If it is different, store the new contents.

var contents = $('.changeable').html();
$('.changeable').blur(function() {
    if (contents!=$(this).html()){
        alert('Handler for .change() called.');
        contents = $(this).html();
    }
});

示例: http://jsfiddle.net/niklasvh/a4QNB/