【发布时间】:2011-07-29 00:57:27
【问题描述】:
我想动态创建一些 HTML 元素(3 个 html 元素),然后将此 html 代码作为字符串返回到变量中。我不想将以下函数中的 HTML 代码写入某个 div,但是,我想将其返回为 var。
function createMyElements(id1,id2,id3){
//create anchor with id1
//create div with id 2
//create xyz with id3
//now return the html code of above created just now
}
我该怎么做?
【问题讨论】:
-
您要创建
elements,还是要创建string元素的表示形式? -
var 中元素的 html 代码,最后我会做 document.getElementbyID("yu").innerHTML = var_containing_code
-
可以使用JS和innerHTML的Template字面量:developer.mozilla.org/de/docs/Web/JavaScript/Reference/…
标签: javascript html dom