Dom &引用;0x80020003-未找到成员“;将变量值传递给样式节点时

Dom &引用;0x80020003-未找到成员“;将变量值传递给样式节点时,dom,autohotkey,Dom,Autohotkey,在下面的代码中,如果我指定属性值,如doc.styleSheets[0].rules[0].style.fontwweight,它会工作,但如果我传递一个变量,它会抛出错误。为什么 html = (Ltrim <html> <head> <style type="text/css"> div { font-weight: bold; } </style> </head&g

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

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)
div{
字体大小:粗体;
}
)
doc:=ComObjCreate(“HTMLfile”)
doc.write(html)
更改规则(文件,“fontweight”、“正常”)
msgbox%doc.documentElement.innerHTML
变更规则(单据、属性、值){
doc.styleSheets[0]。规则[0]。样式[property]:=value;这会导致“错误:0x80020003-找不到成员”
;doc.styleSheets[0]。规则[0]。style.fontweight:=“正常”;此操作有效
}   

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

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
html=
(Ltrim)
div{
字体大小:粗体;
}
)
doc:=ComObjCreate(“HTMLfile”)
doc.write(html)
doc.styleSheets[0]。规则[0]。样式[“fontweight”]:=“正常”;这会导致“错误:0x80020003-找不到成员”
; doc.styleSheets[0]。规则[0]。style.fontweight:=“正常”;这很有效
msgbox%doc.documentElement.innerHTML

据我所知,这是因为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

请将您的解决方案作为答案发布,以便人们知道问题已经解决(未来的读者将找到解决方案)。这本书详细介绍了如何回答你自己的问题——你甚至可以在一段时间后接受它作为正确的答案。(你这样做不会赢得声誉,但这是解决方案正常工作的一个指标。)谢谢。@KenWhite不,这不是一个解决方案。更新的信息缩小了问题的原因。你没看到问题吗?显然,DOM对象不接受键作为要传递的表达式,这在我看来是不寻常的。(我重新措辞)啊,明白了。我把“似乎使用[]会导致错误”和“这有效”误读为您解决了问题的意思。谢谢你的澄清。