2016-07-28 69 views
0

我有一个范围内的iframe。我希望该跨度不可编辑,但不起作用。我尝试了一切:指针事件,contenteditable。什么都没有帮帮我!!如何使跨度不可编辑?

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

是什么'iframeDocument'? –

回答

-1

试着这么做

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

告诉我,如果这个工程。

祝你好运!

+0

不起作用.... – coffeeak

+0

@coffeeak嗯...然后错误将在你没有发布的代码中。你介意制作一个jsfiddle或codepen来展示bug吗? – FelisPhasma

0

添加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 
});