HTML5,draggable and contentEditable not working together

后端 未结 4 2117
-上瘾入骨i
-上瘾入骨i 2020-12-15 06:12

When a draggable attribute is enabled on a parent element(

  • ) I cant make contenteditable work on its child element (<
  • 4条回答
    •  一个人的身影
      2020-12-15 06:37

      I came across the same problem today, and found a solution [using jQuery]

      $('body').delegate('[contenteditable=true]','focus',function(){
          $(this).parents('[draggable=true]')
                  .attr('data-draggableDisabled',1)
                  .removeAttr('draggable');
          $(this).blur(function(){
              $(this).parents('[data-draggableDisabled="1"]')
                      .attr('draggable','true')
                      .removeAttr('data-draggableDisabled');
          });
      });
      

      $('body') can be replaced by anything more specific.

      If new contenteditable elements are not added in the runtime, one can use bind instead of delegate.

    提交回复
    热议问题