2016-07-28 17 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 Hmm ...あなたが投稿していないコードにバグがあります。バグを示すjsfiddleやcodepenを作ってもいいですか? – FelisPhasma

0

iframe要素を選択できるようにcontents()を追加します。

$(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 
}); 
関連する問題