无法使用DOM访问font-weight属性

时间:2012-11-15 12:33:04

标签: dom autohotkey

我在使用DOM访问font-weight属性时遇到了麻烦。

html =
(Ltrim
    <html>
    <head>
    <style type="text/css">
    #bar{
        border: 1px solid black;
    }
    div {
        font-weight: bold;
    }
    </style>
    </head>
    <body><div>foo</div><p id="bar">bar</p></body>
    </html>
)

doc := ComObjCreate("HTMLfile") 
doc.write(html)
msgbox % doc.styleSheets[0].rules[0].style.border           ; "black 1px solid"
msgbox % doc.styleSheets[0].rules[1].style.font-weight      ; nothing
msgbox % doc.styleSheets[0].rules[1].style["font-weight"]   ; "[object]"

这应该是这样吗?或者最后两个消息框是否应显示“粗体”值?

1 个答案:

答案 0 :(得分:3)

-减号用于数学运算,不能用于变量名,因此您遇到的错误。

按照http://www.w3schools.com/jsref/prop_style_fontweight.asp

的建议尝试Object.style.fontWeight="value"之类的内容