读书人

JS 动态创建DIV(IE8没有关问题)Google

发布时间: 2013-10-21 17:03:30 作者: rapoo

JS 动态创—IV(IE8没问题)Google chrome提示:Uncaught TypeError: Illegal invocation
部分代码如下:

提示错误位置为:var backDiv = cDiv("div");
弹出提示Test1没有弹出Test2,想问下这是Google浏览器不支持还是有错误?应该怎么改?谢谢



function setChild(div,kid)
{
//可否移动、调整
var isMove = document.getElementById("isMove").checked;
var isResize = document.getElementById("isResize").checked;

//底色
var cDiv = document.createElement;
alert('Test1');
var backDiv = cDiv("div");
alert('Test2');
backDiv.style.cssText = "left: 0px; top: 0px; width: 100%; height: 100%; background-color: #F5F5F5;";
div.appendChild(backDiv);

//标题
var topDiv = cDiv("div");
topDiv.style.cssText = "left: 2px; top: 2px; width: 100%; height: 30px; position: absolute; background-color: #FF6699; vertical-align: middle; z-index: 5";
if (isMove)
{
topDiv.style.cursor = "move";
topDiv.setAttribute("onmousedown", function(){setMove(this)});
}
else
{
topDiv.style.cursor = "default";
}
topDiv.innerHTML = "<span style='top: 5px; left:5px; font-size: 20px; font-weight: bold; color: #102548; position: relative;' onselectstart='return false'>聊天</span>";
div.appendChild(topDiv);

……(省略)
}

javascript google?chrome 浏览器 js
[解决办法]
var cDiv = document.createElement;
alert('Test1');
var backDiv = cDiv("div");
alert('Test2');

createElement是个方法,
backDiv = document.createElement("div");

读书人网 >JavaScript

热点推荐