[英]javascript code fills html paragraph
best regards, I want to write a javascript code that write to Paragraph <P><br data-mce-bogus="1"></P>
which exists inside this 最好的问候,我想编写一个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>
I tried this code 我尝试了这段代码
javascript:document.getElementById('contentMessage_ifr').contentDocument.body.innerHTML="it works";
is there something wrong with my code , it works fine on w3schools javascript editor 我的代码有问题吗,在w3schools javascript编辑器上工作正常
thanks in advance 提前致谢
Your code is getting the ID of the iframe. 您的代码正在获取iframe的ID。 Try getting a hold of the paragraph.
尝试掌握该段落。 Here's a jsfiddle example which should work: http://jsfiddle.net/kakashi/QR9N8/
这是一个应该起作用的jsfiddle示例: http : //jsfiddle.net/kakashi/QR9N8/
The relevant code you want, if you want to use jQuery, is: 如果要使用jQuery,则所需的相关代码为:
$('p:has(br[data-mce-bogus=1])').append("<p>Hi There</p>");
maybe your html code isn't very clean, you are missing some html tags like "html" and "tr", try this html: 也许您的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.