2012-10-25 113 views
1

最好的問候,我想寫寫到它存在這裏面JavaScript代碼填充HTML段落

<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"; 

<P><br data-mce-bogus="1"></P>一個JavaScript代碼有什麼錯我的代碼,它工作正常上w3schools javascript editor

在此先感謝

+0

http://jsfiddle.net/Wj3CE/似乎工作... –

回答

0

您的代碼正在獲取iframe的ID。 嘗試獲取該段落。 這裏有一個的jsfiddle例子應該工作: http://jsfiddle.net/kakashi/QR9N8/

你想,如果你想使用jQuery,是相關的代碼:

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

也許您的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>​