我无法确定使用哪个选择器来访问 CSS 属性。这是我的代码:
我的jquery:
<script type="text/javascript">
$(document).ready(function () {
$('#columnDay1').css('cursor', 'pointer');
$('#columnDay1').mouseover(function () {
$('td.calendarHeader').css("background-color", "#a43802");
});
$('#columnDay1').mouseout(function () {
$('td.calendarHeader').css("background-color", "#37322e");
});
});
</script>
我的 html:
<div class="contentColumnDay1">
<table cellpadding="0" cellspacing="0" id="columnDay1">
<tr>
<td class="calendarHeader">
<p><span class="dayHeader">Day 1</span><br />August 15, 2011</p>
</td>
</tr>
<asp:Label runat="server" id="labelDay1"></asp:Label>
</table>
我正在尝试访问 .calendarHeader
CSS 属性 background-color
。我试过 #columnDay1.calendarHeader
但它不起作用。我用头撞 table 。
有什么帮助吗?
最佳答案
代替
$('#columnDay1').mouseover(function () {
$('td.calendarHeader').css("background-color", "#a43802");
});
尝试
$('#columnDay1').mouseover(function () {
$('td.calendarHeader', this).css("background-color", "#a43802");
});
td.calendarHeader
将引用类“calendarHeader”的每个 td。您需要为其提供 this
或 $(this)
的上下文,以指定您只想在您刚刚鼠标悬停的元素内找到 td.calendarHeader。或者,您可以执行 $(this).find('td.calendarHeader').css
关于jquery - 无法确定在 div 内表内的 td 上使用什么选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6273565/