html 通过 js 动态添加div

2025-02-14 06:21:51
推荐回答(2个)
回答1:

var com = document.createElement("div");
document.getElementById("XXXX").appendChild(com);
com.x = x;
com.y = y;
com.style.left = "XXpx";
com.style.top = "YYpx";
var txt = document.createElement("input");
txt.nodeType = "text";
com.appendChild(txt);
var btn = document.createElement("input");
btn.nodeType = "button";
btn.onclick = ConfirmComment();
com.appendChild(btn);

回答2:

向所有段落中追加一些HTML标记。

HTML 代码:

I would like to say:



jQuery 代码:
$("p").append("Hello");

结果:
[

I would like to say: Hello

]