对方法或属性访问的意外调用

unexpected call to method or property access

本文关键字:意外 调用 访问 属性 方法      更新时间:2023-09-26

如果你试图在文档的头部添加样式声明,IE会在名称'style' - "意外调用方法或属性访问"处出错。

我猜它混淆了头元素和对象属性。style?

var t = document.createElement("style")
t.setAttribute("type", "text/css");
t.setAttribute("media", "screen");
var temp_text = document.createTextNode(v + " {visibility:hidden}");
t.appendChild(temp_text)

式中v为flash对象id

这可能会有所帮助:http://www.phpied.com/dynamic-script-and-style-elements-in-ie/

对于IE,你必须这样做

    var t = document.createElement("style")
    t.setAttribute("type", "text/css");
    t.setAttribute("media", "screen");
    if(t.styleSheet)
        t.styleSheet.cssText = v + " {visibility:hidden}" ;
    else
    {
        var temp_text = document.createTextNode(v + " {visibility:hidden}");
        t.appendChild(temp_text)
    }