簡體   English   中英

如何使跨度不可編輯?

[英]How to make span non editable?

我在iframe中有一個跨度。 我希望該范圍不可編輯,但是不起作用。 我嘗試了所有事情:指針事件,可編輯內容。 什么都沒有。 救命!!

  $('#tokens-menu-list').on('click', 'li', function() {
        var token       = $(this).attr('data-value');
        var token_style = "border-radius: 5px; background-color: #99CDE1;padding: 5px;cursor: context-menu;";
        $(iframeDocument).find('body').insertAtCaret("<span class='token-item' style='" + token_style + "'>" + token + "</span>");
        $('#tokens-menu').css('display', 'none');
    });



  $(iframeDocument).find('body').on('click', 'span.token-item', function() {
            $(this).css('pointer-events', 'none');
          });

添加contents()以便能夠選擇iframe元素:

 $(iframeDocument).contents().find('body').on('click', 'span.token-item', function(e) {
       e.preventDefault(); // This should stop the click
     // But also, make sure that
      $(this).attr("contenteditable", "false"); // This makes sure that the content can't be edited
});

嘗試類似

$(iframeDocument).find('body').on('click', 'span.token-item', function(e) {
    e.preventDefault(); // This should stop the click
    // But also, make sure that
    $(this).attr("contenteditable", "false"); // This makes sure that the content can't be edited
});

告訴我這是否有效。

祝好運!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM