2

在下面的代码中,如果我指定属性值如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
4

1 回答 1

1

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

这是一个

已知限制:

目前 xy[z]() 被视为 x["y", z](),不支持。作为一种解决方法, (xy)[z]() 首先计算 xy,然后将结果用作方法调用的目标。请注意,xy[z].() 没有此限制,因为它的评估方式与 (xy[z]).() 相同。

像这样试试

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

希望能帮助到你

最好的。

黑圣人

于 2013-05-06T07:52:17.873 回答