利用Javascript函数来给一个DIV上添加按钮等控件?
JS文件中的函数
function create2div() {
//创建DIV var div2 = document.createElement("div");
div2.setAttribute("id", "div2id");
div2.style.position = "absolute";
div2.style.background = "#00FF7F";
div2.style.top = "50";
div2.style.left = "50";
div2.style.width = screen.width / 2 + "px";
div2.style.height = screen.height / 2 + "px";
div2.style.zIndex = "10001";
document.body.appendChild(div2);
//在上面的DIV上创建一个按钮
var button = document.createElement("input"); //创建一个input对象(提示框按钮)
button.setAttribute("type", "button");
button.setAttribute("value", "关闭");
button.style.width = "60px";
button.style.align = "center";
button.style.marginLeft = "250px";
button.style.marginBottom = "10px";
button.style.background = "#000000";
button.style.border = "1px solid " + "#000000";//52
button.style.color = "white";
document.getElementById("div2id").apppendChild(button);
}
但是总是提示行:
56
错误: 对象不支持此属性或方法,不知道是不是DIV这个对象不能引用这个方法吗?appendChild