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