JS实现Table表格中点击一行选中一行


<%--点击一行选中一行--%>
<script>
let old, oldColor;
$("#sp_body tr").click(function(i){
if (old)
oldColor = old.css("background-color",oldColor)
old = $(this)
oldColor = old.css("background-color")
$(this).css("background-color","#ddd")
if ($(this).find(".my").prop('checked')) {
$(this).find(".my").prop("checked",false);

}else{
$(this).find(".my").prop("checked", true);

}

});

$("#sp_body tr").dblclick(function(i) {

if (old)
oldColor = old.css("background-color", oldColor)
old = $(this)
oldColor = old.css("background-color")
$(this).css("background-color", "#ddd")
if ($(this).find("#my").prop('checked')) {
$(this).find("#my").prop("checked",false)
}else{
$(this).find("#my").prop("checked", true)
}

});

</script>

如果更换其他的前端框架,可能需要重新渲染。例如LayUI 需要增加

layui.form.render();来对from表单重新渲染


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM