trigger an event when contenteditable is changed

前端 未结 12 824
抹茶落季
抹茶落季 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 07:02

    In chrome and maybe in other browsers there is bug, when user presses tab it will create space and append apple-be span or some thing like that.. to remove that user

    var contents = $('.changeable').html();
    $('.changeable').blur(function() {
       if (contents!=$(this).html()){
     alert('Handler for .change() called.');
          $(".Apple-tab-span").remove();
           contents = $(this).html();
           contentsTx = $(this).text();
           alert(contentsTx);
    
       }
    });
    

    This will remove the span.. it same as above code just modified it little, or u can add

    .Apple-tab-span
    {
      Display:None;
    }
    

    and this will also solve problem .. http://jsfiddle.net/a4QNB/312/

    Just modified @Nikals answer ...

提交回复
热议问题