将innerHtml的访问器存储为var

storing the accessor to innerHtml as a var

本文关键字:存储 var 访问 innerHtml      更新时间:2023-09-26

我正试图找出一种方法来做以下

var foo = document.body.innerHtml;

then call foo = "testing"

和body的HTML将会是"testing"

但是到目前为止所发生的只是innerHtml返回innerHtml的值…

有没有办法存储innerHtml或者像

var hold = "innerHtml"
document.body[hold] = "foo"  <--- this does not work by the way

您必须使用innerHTML(大写)而不是innerHtml来获得所需的结果。

这些行产生相同的结果:

document.body.innerHTML;
document.body["innerHTML"];
document["body"].innerHTML;
document["body"]["innerHTML"];