将变量值传递给样式节点时,“0x80020003 - 未找到成员”

时间:2012-11-15 14:52:11

标签: dom autohotkey

在下面的代码中,如果我指定属性值如doc.styleSheets[0].rules[0].style.fontweight,它可以工作,但如果我传递一个变量,它会抛出错误。为什么?

html =
(Ltrim
    <html>
    <head>
    <style type="text/css">
    div {
        font-weight: bold;
    }
    </style>
    </head>
    </html>
)

doc := ComObjCreate("HTMLfile") 
doc.write(html)
ChangeCSSRules(doc, "fontweight", "normal")
msgbox % doc.documentElement.innerHTML

ChangeCSSRules(doc, property, value) {
    doc.styleSheets[0].rules[0].style[property] := value    ; this causes "Error:  0x80020003 - Member not found."
    ; doc.styleSheets[0].rules[0].style.fontweight := "normal"  ; this works            
}   

似乎使用[]会导致错误。

html =
(Ltrim
    <html>
    <head>
    <style type="text/css">
    div {
        font-weight: bold;
    }
    </style>
    </head>
    </html>
)

doc := ComObjCreate("HTMLfile") 
doc.write(html)

doc.styleSheets[0].rules[0].style["fontweight"] := "normal" ; this causes "Error:  0x80020003 - Member not found."
; doc.styleSheets[0].rules[0].style.fontweight := "normal"  ; this works            
msgbox % doc.documentElement.innerHTML

1 个答案:

答案 0 :(得分:1)

据我所知,这是因为COM对象的某些属性可以接受参数

那是

  

已知限制:

     

目前x.y [z]()被视为x [“y”,z](),不受支持。   作为解决方法,(x.y)[z]()首先计算x.y,然后使用结果   作为方法调用的目标。请注意,x.y [z]。()没有   这个限制,因为它的评估与(x.y [z])。()。

相同

尝试这样

test:="fontweight"
(doc.styleSheets[0].rules[0].style)[test] := "normal"

希望有所帮助

最好的。

BlackHolyman