繁体   English   中英

JavaScript代码填充html段落

[英]javascript code fills html paragraph

最好的问候,我想编写一个JavaScript代码,将其写入到其中存在的段落<P><br data-mce-bogus="1"></P>

<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编辑器上工作正常

提前致谢

您的代码正在获取iframe的ID。 尝试掌握该段落。 这是一个应该起作用的jsfiddle示例: http : //jsfiddle.net/kakashi/QR9N8/

如果要使用jQuery,则所需的相关代码为:

$('p:has(br[data-mce-bogus=1])').append("<p>Hi There</p>");

也许您的html代码不是很干净,您缺少一些html标签,例如“ html”和“ tr”,请尝试以下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>​

暂无
暂无

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

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