gpt4 book ai didi

Javascript 元素到字符串

转载 作者:行者123 更新时间:2023-12-02 20:22:09 24 4
gpt4 key购买 nike

我正在创建像下面这样的 div 元素,并在 div 和 insideText 中插入一些 html 内容。

var creatediv=document.createElement("DIV");
var html="<div align="left"><a id="test" >test</a></div>";
creatediv.innerHTML=html;
creatediv.innerText="testing";

现在我的问题是如何在此处检索更新的 html 变量。

谢谢

拉吉

最佳答案

您应该能够使用 creatediv.innerHTML 从 creatediv 检索当前 HTML。

var creatediv=document.createElement("DIV");
var html="<div align=\"left\"><a id=\"test\" >test</a></div>";
creatediv.innerHTML=html;
creatediv.innerText="testing";
html = creatediv.innerHTML;

关于Javascript 元素到字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5412307/

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