问题
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