【问题标题】:Alternative command of document.body.innerHTML in prototype js原型js中document.body.innerHTML的替代命令
【发布时间】:2017-10-18 07:11:01
【问题描述】:

document.body.innerHTML 原型的替代命令。

我需要更改原型中文档的 innerhtml 原型 js 中 document.body.innerHTML 的替代命令是什么。

【问题讨论】:

  • 你在 google 上发现了什么?
  • 请告诉我们document.body.innerHTML 附近的哪些内容不适合您。没有“替代品”,那只是多余的。
  • 我想你可以使用$$('body').first().update('your html here');,但如前所述,这只是innerHTML= 的包装。使用 update() 的好处当然是元素将保持扩展(在 Prototype.js 用语中),并且任何插入的元素也将被扩展。换句话说,Prototype 在旧版浏览器中不会停止工作。

标签: javascript prototypejs


【解决方案1】:

如果你有 dom 元素 id,那么你可以使用:

 $('<idOfElement>').update('Text here');

如果您想更改包含标签的 html,则进一步

 $('<idOfElement>').update('<h1>Text here</h1>');

或者如果你想改变body标签本身的内容

 document.body.update('Text here');

如果您想更改包含标签的 html,则进一步

 document.body.update('<h5>Text here</h5>');

我希望这会有所帮助。

【讨论】:

    【解决方案2】:
     //<p> Hello, <b>World</b>!</p>
     var para = document.createElement('p');
      para.appendChild(document.createTextNode('Hello, '));
    
     // <b>
     var b = document.createElement('b');
     b.appendChild(document.createTextNode('World');
    para.appendChild(b);
    
    para.appendChild(document.createTextNode('!'));
    
    // Do something with the para element, add it to the document, etc.
    

    还有,

      var node = document.getElementById("one");
    
     while( node.firstChild )
        node.removeChild( node.firstChild );
        node.appendChild( document.createTextNode("Two") );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多