Short answer: you can't.
(简短的答案:您不能。)
Long answer: you shouldn't.
(长答案:你不应该。)
Give it a class name or an id and use stylesheets to apply the style.
(给它一个类名或一个ID,并使用样式表来应用样式。)
:hover
is a pseudo-selector and, for CSS , only has meaning within the style sheet.
(:hover
是一个伪选择器,对于CSS而言 ,仅在样式表中具有含义。)
There isn't any inline-style equivalent (as it isn't defining the selection criteria). (没有任何等效的内联样式(因为它没有定义选择标准)。)
Response to the OP's comments:
(回应OP的评论:)
See Totally Pwn CSS with Javascript for a good script on adding CSS rules dynamically.
(有关动态添加CSS规则的良好脚本,请参见带有Javascript的Totally Pwn CSS 。)
Also see Change style sheet for some of the theory on the subject. (另请参阅更改样式表以获取有关该主题的一些理论。)
Also, don't forget, you can add links to external stylesheets if that's an option.
(另外,不要忘记,如果可以的话,您可以添加到外部样式表的链接。)
For example, (例如,)
<script type="text/javascript">
var link = document.createElement("link");
link.setAttribute("rel","stylesheet");
link.setAttribute("href","http://wherever.com/yourstylesheet.css");
var head = document.getElementsByTagName("head")[0];
head.appendChild(link);
</script>
Caution: the above assumes there is a head section.
(注意:以上假设存在头部 。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…