如何使用 Javascript/CSS 更新 IE 中的表格行背景颜色?
我有一个表,我想在鼠标悬停/鼠标移出期间“突出显示”。我已经知道这在 IE 中是必需的,但在其他浏览器中不是必需的。
我已经成功检测到事件触发,并且此 TR 标签有效地工作。 (请注意,原始类“contentTableRow”似乎没有引起任何问题。)
class="contentTableRow" onclick="openForm('SomeID');" onmouseover="highlight('someRowID', true);" onmouseout="highlight('someRowID', false);" id="someRowID"
一切都很好,“突出显示”函数触发并实际上设置了适当的类。
只是IE不会处理CSS类名的改变。
这是我用来进行更改的 CSS 片段。
.HighlightOn {
cursor:pointer;
background-color: #D1DFFF;
}
.HighlightOff {
background-color: #E1EEFE;
}
当我调试它时,我可以看到类名称正在更新,并且还在 Firebug 中检查它。但 IE 似乎不喜欢使用带有 TR 标签的类。这是我为 Tables 构建类的方式吗?有什么建议吗?
I have a table that i want to "highlight" during onmouseover/onmouseout. I already know this is required in IE but not in other browsers.
I have managed to detect the events triggering and this TR tag effectively works. (Note that the originating class "contentTableRow" doesn't seem to be causing any issues.)
class="contentTableRow" onclick="openForm('SomeID');" onmouseover="highlight('someRowID', true);" onmouseout="highlight('someRowID', false);" id="someRowID"
All is fine and dandy, the "highlight" function fires and actually sets the appropriate class.
It's just that IE won't process the CSS class name change.
Here is a snippet of the CSS I am using to make the change.
.HighlightOn {
cursor:pointer;
background-color: #D1DFFF;
}
.HighlightOff {
background-color: #E1EEFE;
}
I can see that the Class names are getting updated when I debug it, and also check it in Firebug. But it seems that IE doesn't like this usage of classes with a TR tag.. Is it the way I am structuring the class for Tables ? Any advice ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否正在更改
class
而不是className
?class
在 Javascript 中保留为实际的类声明关键字,因此该属性称为className
:顺便说一句,您可能只想传递“this”来突出显示而不是 id ,因此不需要执行
document.getElementById()
调用Are you changing
class
instead ofclassName
?class
is reserved in Javascript as the actual class declaration keyword, so the property is calledclassName
:Incidentally, you might just want to pass "this" to highlight instead of the id, so it doesn't need to do the
document.getElementById()
call感谢所有的指点。但这似乎起了作用。
在这种情况下,基本上必须明确该类在 HTML 中的使用位置。
请注意,我必须引用与表中使用 Highlighton/off 类相关的 TR 标记和 TD 标记。谢谢詹斯格拉姆。
希望这可以帮助其他遇到同样问题的人。
(感谢 Jensgram 的领导)
Thanks for all the pointers. But this seems to have worked.
Basically have to be explicit in this case about where the class is used in the HTML.
Note that I had to reference the TR tag and the TD tags relative to where I am using the Highlighton/off classes in the table. Thanks jensgram.
Hope this helps anyone else with the same problem.
(thanks Jensgram for the lead)
IE 无法识别 JavaScript 中的“类”。您必须使用“className”作为 IE 中的属性。
IE won't recognize "class" in JavaScript. You must use "className" as the property in IE.