简体   繁体   English

如何使跨度不可编辑?

[英]How to make span non editable?

I have a span inside an iframe. 我在iframe中有一个跨度。 I want that span to be non-editable, but doesn't work. 我希望该范围不可编辑,但是不起作用。 I tried everything: pointer-events, contenteditable. 我尝试了所有事情:指针事件,可编辑内容。 Nothing works. 什么都没有。 Help!! 救命!!

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

Add contents() to be able to select iframe elements : 添加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
});

Try something like 尝试类似

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

Tell me if this works. 告诉我这是否有效。

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM