【发布时间】:2012-03-20 10:41:58
【问题描述】:
在下面的 sn-p 代码中,我想单击顶部框来切换颜色,但 jQuery 没有正确引用该对象。任何帮助将不胜感激。该框用 id='tst' 的表标记。框本身是一个 td 单元格,它是 id 选择器“tst”(在 css 中定义)的类型选择器。 jQuery 不知何故没有引用该对象。请参阅下面的代码。底框仅供参考...
<html><head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#tst td").click(function(){
$(this).toggleClass('green');
});
});
</script>
<style type="text/css">
table#tst {border:solid 1px;}
#tst td
{background-color: red;}
.green {background-color:green;}
</style>
</head>
<body>
<p>Click the top box to toggle color between red and green.<br> Bottom box is for reference.</p>
<table id="tst"><tr><td width=50 height=50></td></tr></table>
<br>
<table border=1><tr><td width=50 height=50></td></tr></table>
</body>
</html>
【问题讨论】:
标签: jquery css types jquery-selectors