trigger an event when contenteditable is changed

前端 未结 12 803
抹茶落季
抹茶落季 2020-11-29 06:14

When a divs value is changed, how Can I trigger an event?

Click this div to edit it
12条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-29 06:44

    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();
        }
    });
    

    example: http://jsfiddle.net/niklasvh/a4QNB/

提交回复
热议问题