首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

js中如何往iframe中添加一个div

2012-04-12 
js中怎么往iframe中添加一个diviframe idshowValue stylewidth: 400px height: 95px border: 0px

js中怎么往iframe中添加一个div
<iframe id="showValue" style="width: 400px; height: 95px; border: 0px; solid: #000;"
  src="about:blank"></iframe>
 
<script type="text/javascript">
  window.onload = function () {
  document.getElementById("showValue").contentWindow.document.designMode = "on";
  document.getElementById("showValue").contentWindow.document.contentEditable = true;
  }
</script>
如何往iframe中添加一个div,并且给div赋一个id值

[解决办法]

HTML code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>    <title></title></head><body><iframe id="showValue" style="width: 400px; height: 400px; border: 0px; solid: #000;" src="about:blank"></iframe>  <script type="text/javascript">    window.onload = function () {        document.getElementById("showValue").contentWindow.document.designMode = "on";        document.getElementById("showValue").contentWindow.document.contentEditable = true;        var div = document.createElement("DIV");        div.id = "divName";        div.innerHTML = "我在这里了哈";        div.style.cssText = "border:1px solid #ccc;height:200px;width:200px;color:red;";        document.getElementById("showValue").contentWindow.document.appendChild(div);    }</script></body></html> 

热点排行