// Delete all columns except the first column $ ('#table1 tr th:not(:nth-child(1))').remove(); $('#table1 tr td:not(:nth-child(1))').remove( ); //Delete the first column $('#table1 tr td::nth-child(1)').remove();
// Set table1, The value of the first td of the second tr. $('#table1 tr:eq(1) td:nth-child(1)').html('value'); // Get table1, the first td of the second tr value. $('#table1 tr:eq(1) td:nth-child(1)').html();
//Method zero: $('#all').on('click', function () { $('input.checkSub').prop('checked', this.checked); // Add effects to the currently bound sub-selections });
//Method 1: //Select all or not select all. The parameter passed in is event. For example: checkAll(event) function checkAll(evt){ evt=evt?evt: window.event; var chall=evt.target?evt.target:evt.srcElement; var tbl=$("#table1"); var trlist=tbl.find("tr") ; for(var i=1;i var tr=$(trlist[i]); var input=tr.find("INPUT[type=' checkbox']"); input.attr("checked",chall.checked); } } //Method 2: //Select all or none The parameter passed in is this, such as: checkAll(this) function checkAll(evt){ var tbl=$("#table1"); var trlist=tbl.find("tr"); for(var i=1;i var tr=$(trlist[i]); var input=tr.find("INPUT[type='checkbox ']"); input.attr("checked",evt.checked); } } //Method 3: //Select all or none The input parameter is this. For example: checkAll(this) function checkAll(evt){ $("#table1 tr").find("input[type='checkbox']").each(function( i){ $(this).attr("checked",evt.checked) }); } //Method 4: //Select all or none The parameter passed in is this. For example: checkAll(this) function checkAll(evt){ $("#table1 tr").find("input[type='checkbox']").attr( "checked",evt.checked); }
function btnAddRow(){ //The row number starts from 0, and the last row is the add, delete, save button, so subtract 2 var rownum=$( "#table1 tr").length-2; var chk=""; var text=""; var sel=""; var row="
" chk "
" text "
" sel "
" text "
" text "
"; $(row).insertAfter($("#table1 tr:eq(" rownum ")") ; The code is as follows:
Only one row can be deleted at a time. An error occurs when deleting multiple rows. function btnDeleteRow(){ $("#table1 tr").find(" input[type='checkbox']").each(function(i){ if($(this).attr("checked")){
function btnSaveClick(){ //I don’t know how to set multiple filter conditions in the find() method, so I can’t get the value of the select list below //$(" #table1 tr td").find("input[type='text']" || "select").each(function(i){ //alert($(this).val()); //}); ='text']").length>0){ alert($(this).find("input[type='text']").val()); (this).find("select").length>0) { alert($(this).find("select").val()); } }) ; }
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn