


Detailed explanation of how to use jquery to add, save, and delete table data
We often do not process this data by submitting forms, because it is very cumbersome to traverse and process these large amounts of data in the background; a better approach is to save the data in json in the form of objects in the front-end page , and then directly convert json into the object we need in the background, so that we can directly process the object!
Add button
<input name="button" type="button" value="添加" onClick="addRowForPswdBasicFillTemplate('pswd_basic_fill_template')">
table id is pswd_basic_fill_template
Add method
function addRowForPswdBasicFillTemplate(tid){ var applyAreaOptionStr = $('#applyAreaOptionStr').val(); //这里是对select框的一些初始化 did = tid; var tr = $("<tr></tr>").attr("bgcolor","#FFFFFF"); tr.append($("<td></td>").html("<input type='radio' name='radio' value='checkbox'></td>")); tr.append($("<td></td>").html("")); tr.append($("<td></td>").html("<input type='text' name='index_name' id='index_name' />")); tr.append($("<td></td>").html("")); tr.append($("<td></td>").html("<select name='apply_Area' id='apply_Area'>"+applyAreaOptionStr+"</select>")); tr.append($("<td></td>").html("<select name='index_species' id='index_species'>"+$("#indexSpeciesHtml").val()+"</select>")); tr.append($("<td></td>").html("<textarea maxlength='500' rows='3' cols='20' name='formula' id='formula'/>")); tr.append($("<td></td>").html("<input type='text' name='cap' id='cap' size='5'/>")); tr.append($("<td></td>").html("<input type='text' name='base_value' id='base_value' size='5'/>")); tr.append($("<td></td>").html("<input type='hidden' id='orgid' name='orgid' /> <select name='assessOrg' id='assessOrg'>"+$("#assessOrgHtml").val()+"</select>")); tr.appendTo($("#"+tid)); setRowNumber_1(tid); //保存编号,上移下移操作会用到 ,先不关注 }
Save button
<input name="button" type="button" value="保存" onClick="savePswdBasicFillTemplate('pswd_basic_fill_template')">
Save method
function savePswdBasicFillTemplate(tid){ did = tid; var result = getPswdBasicFillTemplate(); //封装数据操作,请仔细看 if(result){ /* if(pswd_basic_fill_template.length<1){ showInfo("请添加基础数据标准"); return; } */ for(var i=0;i<pswd_basic_fill_template.length;i++){ pswd_basic_fill_template[i]=JSON.stringify(pswd_basic_fill_template[i]); } $.post("<c:url value='/secbasicFillTemplate/save'/>",{"tempLateList":"["+pswd_basic_fill_template+"]"}, function(data) { if("false"==data){ showInfo("请先保存基础信息!"); }else{ //delAllTr("pswd_basic_fill_template"); //删除行 showInfo("保存成功!") if(did!="fjsjbz"){ changeTaskType(tid); } } }); } } //基础填报模版 var pswd_basic_fill_template = {}; //要删除的tableId var did = "pswd_basic_fill_template"; //获取模板值 function getPswdBasicFillTemplate(){ pswd_basic_fill_template=[]; var trs=eval("$(\"#"+did + " tbody tr\")"); var result=true; $.each(trs,function(i,tr){ var order = $(tr).find("td:nth-child(2)").text(); var indexCode = $(tr).find("input[name='index_code']").val(); var indexName = $(tr).find("input[name='index_name']").val(); var indexType = $(tr).find("select[name='index_type']").find("option:selected").text(); var indexSpecies = $(tr).find("select[name='index_species']").find("option:selected").text(); var formula = $(tr).find("textarea[name='formula']").val(); var cap = $(tr).find("input[name='cap']").val(); var baseValue = $(tr).find("input[name='base_value']").val(); var assessOrg = $(tr).find("select[name='assessOrg']").val(); var assessOrgName = $(tr).find("select[name='assessOrg']").find("option:selected").text(); var idObj = $(tr).find("input[name='idObj']").val(); var indexValue = $(tr).find("input[name='index_value']").val(); var templateType = "2"; if(did=="zdppbzlb"){ templateType = "3"; }else if(did=="fjsjbz"){ templateType = "4"; assessOrg = $(tr).find("select[name='countyOrg']").val(); } var taskType = $("#task_type").val(); if(indexCode.length<1){ showInfo("指标名称不能为空"); result = false; return false; } if(indexName.length<1){ showInfo("指标代号不能为空"); result = false; return false; } var postIndexId = $('#postIndex').val(); var postIndexName = $('#postIndex').find("option:selected").text(); var applyAreaId = $(tr).find("select[name='apply_Area']").val(); var applyAreaName = $(tr).find("select[name='apply_Area']").find("option:selected").text(); var pswd_basic_fill_templateBean={ "postIndexId":postIndexId,"postIndexName":postIndexName,"applyAreaId":applyAreaId,"applyAreaName":applyAreaName, "indexCode":indexCode,"templateType":templateType,"indexValue":indexValue, "indexName":indexName,"taskType":taskType,"order":order,"id":idObj,"baseValue":baseValue, "indexSpecies":indexSpecies,"formula":formula,"cap":cap,"orgName":assessOrgName,"orgid":assessOrg } pswd_basic_fill_template.push(pswd_basic_fill_templateBean); }) return result; }
The front-end operation is completed, let’s take a look at the background operation
struts configuration file
<method name="save" uri="/secbasicFillTemplate/save"> <result name="success" type="redirect">@list</result> <result name="failed">secassessment/basicFillTemplate/basicFillTemplateNew</result> </method>
Background operation
public void save() { String obj = request().getParameter("tempLateList"); List<SecBasicFillTemplate> result = JSonUtil.paserJsonArray(SecBasicFillTemplate.class,obj); //将json转化为对象 }
Let’s take a look at the delete operation
Delete button
//删除一行的数据 function delRowForSpacialById(tid){ var selObj=getSelRowJnSpacial(tid); if(selObj){ var result = confirm("确定将记录删除?"); if(result){ var id = selObj.parent().parent(); var idValue = id.find("input[name='idObj']").val(); if(idValue!=null && idValue.length>0){ $.post("<c:url value='/secbasicFillTemplate/delete'/>",{"ids":idValue},function(){ selObj.parent().parent().remove(); }) }else{ selObj.parent().parent().remove(); } } } } // 获取选中的行 function getSelRowJnSpacial(tid){ var selObj=eval("$(\"#"+tid+" input[@type=radio][checked]\")"); if(selObj.html()!=null){ return selObj; }else{ showInfo("请选择要操作的行"); return null; } } struts 配置文件 <method name="delete" uri="/secbasicFillTemplate/delete" > <result name="success" type="redirect">@list</result> </method> 后台方法 public void delete(String ids) { //方法 } 上移下移功能 按钮 <input name="button" type="button" value="上移" onClick="moveBefore('pswd_basic_fill_template')"> <input name="button" type="button" value="下移" onClick="moveAfter('pswd_basic_fill_template')"> //上移行 function moveBefore(tid){ did =tid; var selObj= $("input:radio[checked]"); if(selObj==null){ showInof("请选择要移动的行"); }else{ var rowIndex = selObj.parent().parent()[0].rowIndex; if(parseInt(rowIndex)<=2){ showInfo("已经到顶,不能再上移了"); return; } var preObj=selObj.parent().parent().prev(); var selRow=selObj.parent().parent().clone(); preObj.before(selRow); selObj.parent().parent().remove(); setRowNumber_1_1(did); } } function setRowNumber_1_1(tid){ var fNew = 1; var expression="$(\"#"+tid+" tbody tr\")"; var tbody=eval(expression); $.each(tbody,function(i,tr){ if(i>=0){ var number=i+1; $(tr).find("td:nth-child(2)").text(number); } }) } //下移行 function moveAfter(tid){ did =tid; var selObj= $("input:radio[checked]"); if(selObj==null){ showInof("请选择要移动的行"); }else{ var r1 = selObj.parent().parent()[0].rowIndex; var a1 = eval("$(\"#"+did+" tbody tr\")").size(); if(parseInt(selObj.parent().parent()[0].rowIndex)-1 >= a1){ showInfo("已经到最后一行,不能再下移了"); return; } var nextObj=selObj.parent().parent().next(); var selRow=selObj.parent().parent().clone(); nextObj.after(selRow); selObj.parent().parent().remove(); setRowNumber_1_1(tid); } } //设置rowNumber的序号 function setRowNumber_1(tid){ var fNew = 1; var expression="$(\"#"+tid+" tbody tr\")"; var tbody=eval(expression); $.each(tbody,function(i,tr){ if(i>=0){ var idObj = $(tr).find("input[name='idObj']").val(); var f = $(tr).find("td:nth-child(4)").find("input[name='index_code']").val(); if(f!=null){ var f1 = f.substring(1); if(f1>=0){ fNew = parseInt(f1)+1; } } var number=i+1; $(tr).find("td:nth-child(2)").text(number); if(idObj==null && f==null){ var fValue = "<input id='index_code' name='index_code' value='F"+fNew+"' readonly='true' size='5'>"; if(tid=="zdppbzlb"){ fValue = "<input id='index_code' name='index_code' value='K"+fNew+"' readonly='true' size='5'>"; } $(tr).find("td:nth-child(4)").html(fValue); $(tr).find("td:nth-child(5)").html($("#selectHtml").val()); //var assessOrgHtml = "<input type='hidden' name='orgid' id='orgid'></input>"+$("#assessOrgHtml").val(); //$(tr).find("td:last-child").html(assessOrgHtml); } } }) }
The above is the detailed content of Detailed explanation of how to use jquery to add, save, and delete table data. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



1. Create a new PPT file and name it [PPT Tips] as an example. 2. Double-click [PPT Tips] to open the PPT file. 3. Insert a table with two rows and two columns as an example. 4. Double-click on the border of the table, and the [Design] option will appear on the upper toolbar. 5. Click the [Shading] option and click [Picture]. 6. Click [Picture] to pop up the fill options dialog box with the picture as the background. 7. Find the tray you want to insert in the directory and click OK to insert the picture. 8. Right-click on the table box to bring up the settings dialog box. 9. Click [Format Cells] and check [Tile images as shading]. 10. Set [Center], [Mirror] and other functions you need, and click OK. Note: The default is for pictures to be filled in the table

DDREASE is a tool for recovering data from file or block devices such as hard drives, SSDs, RAM disks, CDs, DVDs and USB storage devices. It copies data from one block device to another, leaving corrupted data blocks behind and moving only good data blocks. ddreasue is a powerful recovery tool that is fully automated as it does not require any interference during recovery operations. Additionally, thanks to the ddasue map file, it can be stopped and resumed at any time. Other key features of DDREASE are as follows: It does not overwrite recovered data but fills the gaps in case of iterative recovery. However, it can be truncated if the tool is instructed to do so explicitly. Recover data from multiple files or blocks to a single

0.What does this article do? We propose DepthFM: a versatile and fast state-of-the-art generative monocular depth estimation model. In addition to traditional depth estimation tasks, DepthFM also demonstrates state-of-the-art capabilities in downstream tasks such as depth inpainting. DepthFM is efficient and can synthesize depth maps within a few inference steps. Let’s read about this work together ~ 1. Paper information title: DepthFM: FastMonocularDepthEstimationwithFlowMatching Author: MingGui, JohannesS.Fischer, UlrichPrestel, PingchuanMa, Dmytr

Being able to skillfully make forms is not only a necessary skill for accounting, human resources, and finance. For many sales staff, learning to make forms is also very important. Because the data related to sales is very large and complex, and it cannot be simply recorded in a document to explain the problem. In order to enable more sales staff to be proficient in using Excel to make tables, the editor will introduce the table making issues about sales forecasting. Friends in need should not miss it! 1. Open [Sales Forecast and Target Setting], xlsm, to analyze the data stored in each table. 2. Create a new [Blank Worksheet], select [Cell], and enter [Label Information]. [Drag] downward and [Fill] the month. Enter [Other] data and click [

1. Open the worksheet and find the [Start]-[Conditional Formatting] button. 2. Click Column Selection and select the column to which conditional formatting will be added. 3. Click the [Conditional Formatting] button to bring up the option menu. 4. Select [Highlight conditional rules]-[Between]. 5. Fill in the rules: 20, 24, dark green text with dark fill color. 6. After confirmation, the data in the selected column will be colored with corresponding numbers, text, and cell boxes according to the settings. 7. Conditional rules without conflicts can be added repeatedly, but for conflicting rules WPS will replace the previously established conditional rules with the last added rule. 8. Repeatedly add the cell columns after [Between] rules 20-24 and [Less than] 20. 9. If you need to change the rules, you can just clear the rules and then reset the rules.

The performance of JAX, promoted by Google, has surpassed that of Pytorch and TensorFlow in recent benchmark tests, ranking first in 7 indicators. And the test was not done on the TPU with the best JAX performance. Although among developers, Pytorch is still more popular than Tensorflow. But in the future, perhaps more large models will be trained and run based on the JAX platform. Models Recently, the Keras team benchmarked three backends (TensorFlow, JAX, PyTorch) with the native PyTorch implementation and Keras2 with TensorFlow. First, they select a set of mainstream

Facing lag, slow mobile data connection on iPhone? Typically, the strength of cellular internet on your phone depends on several factors such as region, cellular network type, roaming type, etc. There are some things you can do to get a faster, more reliable cellular Internet connection. Fix 1 – Force Restart iPhone Sometimes, force restarting your device just resets a lot of things, including the cellular connection. Step 1 – Just press the volume up key once and release. Next, press the Volume Down key and release it again. Step 2 – The next part of the process is to hold the button on the right side. Let the iPhone finish restarting. Enable cellular data and check network speed. Check again Fix 2 – Change data mode While 5G offers better network speeds, it works better when the signal is weaker

I cry to death. The world is madly building big models. The data on the Internet is not enough. It is not enough at all. The training model looks like "The Hunger Games", and AI researchers around the world are worrying about how to feed these data voracious eaters. This problem is particularly prominent in multi-modal tasks. At a time when nothing could be done, a start-up team from the Department of Renmin University of China used its own new model to become the first in China to make "model-generated data feed itself" a reality. Moreover, it is a two-pronged approach on the understanding side and the generation side. Both sides can generate high-quality, multi-modal new data and provide data feedback to the model itself. What is a model? Awaker 1.0, a large multi-modal model that just appeared on the Zhongguancun Forum. Who is the team? Sophon engine. Founded by Gao Yizhao, a doctoral student at Renmin University’s Hillhouse School of Artificial Intelligence.
