开发者

Javascript function not working cross-browser.

This is my javascript function that is working in chrome and FF5 but not working in IE.

function createContorl() {
    var parentDiv = document.createElement("div");

    parentDiv.setAttribute("class", "ModelProgressDiv");
    parentDiv.setAttribute("Id", "ProgressDiv");

    var innerContent = document.createElement("div");

    innerContent.setAttribute("class", "ModalProgressDi开发者_开发知识库vContent");

    var img = document.createElement("img");

    img.setAttribute("src", "images/loading_large.gif");
    parentDiv.appendChild(innerContent);

    innerContent.appendChild(img);
    document.body.appendChild(parentDiv);
}


setAttribute is broken in IE unless you are using a very recent version in Standards Mode. It sets properties instead of attributes so it fails when the property doesn't have the same name as the attribute. Don't use it.

parentDiv.className = "ModelProgressDiv"; // etc


Your code works fine on IE8: see this fiddle

BTW, please check the in the function name createContorl but that would cause problem in all browsers.

Perhaps, you should explain when you say "not working in IE".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜