在我的网页上,我有一个表格,我想更改一行的背景,在此过程中,单击该行时选中与该行对应的单选按钮。我使用 jquery 尝试了以下操作:
<style>
.active { background-color: #8fc3f7;}
</style>
<script>
$(document).ready(function()
{
$('#reqtablenew tr').click(function ()
{
$('#reqtablenew tr').removeClass("active");
$(this).addClass("active");
});
});
<script>
任何关于我可能做错了什么或任何解决方法的想法都将非常受欢迎。我在页面中包含了以下脚本。 src="http://code.jquery.com/jquery-1.9.1.js"> 和 src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"
这是我 table 上的 fiddle http://jsfiddle.net/Gz668/5/
最佳答案
你忘了添加jquery
在你的 css 中添加这个
tr.active td {
background-color: #8fc3f7;
}
我已将您的演示更新为 this
已更新以检查 radio
试试这个,
$(this).find('[name="reqradio"]').prop('checked',true);
完整代码
$(document).ready(function () {
$('#reqtablenew tr').click(function () {
$('#reqtablenew tr').removeClass("active");
$(this).addClass("active");
$(this).find('[name="reqradio"]').prop('checked',true);
});
});
关于javascript - 单击更改表格行的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19970983/