Cannot access font-weight property with DOM

醉酒当歌 提交于 2019-12-11 05:06:05

问题


I'm having troubles accessing the font-weight property with DOM.

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]"

Is this supposed to be this way? Or should the last two message boxes show the value "bold"?


回答1:


The - Minus sign is used in mathematical operations and cannot be used in a variable name, hence the error you are experiencing.

Try something like Object.style.fontWeight="value" as suggested at http://www.w3schools.com/jsref/prop_style_fontweight.asp



来源:https://stackoverflow.com/questions/13397614/cannot-access-font-weight-property-with-dom

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!