gpt4 book ai didi

javascript代码填充html段落

转载 作者:行者123 更新时间:2023-11-28 09:35:46 24 4
gpt4 key购买 nike

最诚挚的问候,我想编写一段 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 editor 上运行良好

提前致谢

最佳答案

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

如果你想使用 jQuery,你想要的相关代码是:

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

关于javascript代码填充html段落,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13072568/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com