1

<P><br data-mce-bogus="1"></P>この中に存在するParagraph に書き込む JavaScript コードを書きたいと思います。

<html><head>
</head>
<body>
<table id="contentMessage_tbl" class="mceLayout" cellspacing="0" cellpadding="0" role="presentation" style="width: 100%; height: 260px;">
<tbody>
<td class="mceIframeContainer mceFirst mceLast">
<iframe id="contentMessage_ifr" frameborder="0" src="javascript:""" allowtransparency="true" title="Rich Text AreaPress ALT-F10 for toolbar. Press ALT-0 for help" style="width: 100%; height: 216px; display: block;">
<head xmlns="http://www.w3.org/1999/xhtml">
<meta content="IE=7" http-equiv="X-UA-Compatible">
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body id="tinymce" class="mceContentBody " contenteditable="true" spellcheck="false" dir="ltr" style="font-size: 12px; font-family: arial,helvetica,sans-serif;">
<p>
<br data-mce-bogus="1">
</p>
</body>
</html>
</iframe>
</td>
</tbody>
</table>
</body>
</html>

このコードを試しました

javascript:document.getElementById('contentMessage_ifr').contentDocument.body.innerHTML="it works";

私のコードに何か問題がありますか? w3schools JavaScriptエディターで問題なく動作します

前もって感謝します

4

2 に答える 2

0

おそらくあなたの html コードはあまりきれいではなく、"html" や "tr" のようないくつかの html タグが欠けています。次の html を試してください:

<html>
<head>
</head>
<body>
<table id="contentMessage_tbl" class="mceLayout" cellspacing="0" cellpadding="0" role="presentation" style="width: 100%; height: 260px;">
<tbody><tr>
<td class="mceIframeContainer mceFirst mceLast">
<iframe id="contentMessage_ifr" frameborder="0" src="javascript:"""   allowtransparency="true" title="Rich Text AreaPress ALT-F10 for toolbar. Press ALT-0 for  help" style="width: 100%; height: 216px; display: block;">
<html>
<head xmlns="http://www.w3.org/1999/xhtml">
<meta content="IE=7" http-equiv="X-UA-Compatible">
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body id="tinymce" class="mceContentBody " contenteditable="true" spellcheck="false" dir="ltr" style="font-size: 12px; font-family: arial,helvetica,sans-serif;">
<p>
<br data-mce-bogus="1">
</p>
</body>
</html>
</iframe>
</td></tr>
</tbody>
</table>
</body>
</html>​
于 2012-10-25T16:17:13.663 に答える
0

あなたのコードは iframe の ID を取得しています。段落をつかんでみてください。動作するはずのjsfiddleの例を次に示します: http://jsfiddle.net/kakashi/QR9N8/

jQuery を使用する場合に必要な関連コードは次のとおりです。

$('p:has(br[data-mce-bogus=1])').append("<p>Hi There</p>");
于 2012-10-25T16:07:02.553 に答える