[英]Jquery problem animation or not animation
First of all I'm new to jquery, so I don't know if it's possible, hence my question.首先,我是 jquery 的新手,所以我不知道这是否可能,因此是我的问题。
I have a problem to solve, but my doubt is it possible to solve it without animation or I will have to switch to animation.我有一个问题要解决,但我怀疑是否可以在没有 animation 的情况下解决它,否则我将不得不切换到 animation。
<script type="text/javascript">
$().ready( function() {
$('table').on('click', 'tr', function () {
if ($(this).hasClass('active')) {
$(this).removeClass('active');
$(this).addClass('inactive');
}
});
$( "div" ).html( " <table class='table'><tbody><tr class='active'> <td><span>Row 1</span></td><td><span>Row 1 </span></td> <td><span>Row 1</span></td></tr></tbody></table>" );
})
</script>
<style type="text/css">
.active{
background-color:gray;
}
.inactive{
background-color:white ;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
$(document).ready(function() { $("div").html(" <table class='table'><tbody><tr class='active'> <td><div class='row active'>Row 1</div></td><td><div class='row'>Row 1 </div></td> <td><div class='row'>Row 1</div></td></tr></tbody></table>"); $('.row').on('click', function() { if ($(this).toggleClass('active')) { $(this).removeClass('active'); $(this).toggleClass('inactive'); } }); })
.active { background-color: gray; }.inactive { background-color: white; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div></div>
You can switch color.你可以切换颜色。 Please check this
请检查这个
Thanks I kind of modified something in your code and it turned out the way I wanted谢谢我在你的代码中修改了一些东西,结果是我想要的
$(document).ready(function() {
$("div").html(" <table class='table'><tbody><div ><tr class='row active'> <td>Row 1</td><td>Row 1 </td> <td>Row 1</td></tr></tbody></table>");
$('.row').on('click', function() {
if ($(this).toggleClass('active')) {
$(this).removeClass('active');
$(this).toggleClass('inactive');
}
});
})
instead of being per item i changed it to be by the whole row而不是每个项目,我将其更改为整行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.