Javascript 四、htmlcopy//创建一个新的div容器 $'.error列'.appenddiv//将所有HTML插入到新的div中 $'addRow\'+btnId.propdisabled,true//单击后禁用“添加”按钮。 }; //从列表中删除文本字段并
四、htmlcopy//创建一个新的div容器 $'.error列'.appenddiv//将所有HTML插入到新的div中 $'addRow\'+btnId.propdisabled,true//单击后禁用“添加”按钮。 }; //从列表中删除文本字段并重置错误号 $document.on'click','.delRow',函数{ var//btnId=$this.databid.match/\d+/,//使用.match从ID中断开数字 maxNoList=$'input[class=addRow]'。长度, errNoList=maxNoList-1; //btnId=btnId-1;//计算上一个按钮的ID号 $'addRow\'+errNoList.prop'disabled',false;//启用上一个添加按钮 $'stValue'.valernolist;//删除文本字段时设置stValue的值 //因此,当再次单击“添加”时,将相应地生成错误号。 $this.parent.remove;//从列表中删除文本行。 重新安排; }; }; 功能重组{ $.errorCount.eachfunctionindex,\u此{ $this.valindex+1; }; } //HTML函数,该函数将由添加按钮的按钮单击事件调用 功能副本{ var stNum=document.getElementByIdstValue, genNum=document.getElementByIdstValue.value-1+2; stNum.value=genNum; //语言=HTML 返回'\n'+ “\n”+ “---选择错误---\n”+ “\n”+ “\n”+ } 错误编号错误名称 ---选择错误---Javascript 四、htmlcopy//创建一个新的div容器 $'.error列'.appenddiv//将所有HTML插入到新的div中 $'addRow\'+btnId.propdisabled,true//单击后禁用“添加”按钮。 }; //从列表中删除文本字段并,javascript,jquery,Javascript,Jquery,四、htmlcopy//创建一个新的div容器 $'.error列'.appenddiv//将所有HTML插入到新的div中 $'addRow\'+btnId.propdisabled,true//单击后禁用“添加”按钮。 }; //从列表中删除文本字段并重置错误号 $document.on'click','.delRow',函数{ var//btnId=$this.databid.match/\d+/,//使用.match从ID中断开数字 maxNoList=$'input[class=add
很难理解你想做什么。。你能提供一个JSFIDLE并向我们解释一下数字序列被弄乱意味着什么吗?@oliv37 JSFIDLE补充道。很难理解你想做什么。。“你能提供一个JSFIDLE并向我们解释数字序列被弄乱意味着什么吗?”oliv37 JSFIDLE补充道。
//Add and remove function for the error text boxes
$(document).ready(function () {
$(document).on('click','.addRow',function () {
var div = $("<div />"),
btnId = $(this).data("bid").match(/\d+/);//Breaks the number from the ID using .match
div.html(copy()); //Creates a new div container
$('.error-Column').append(div); //Insert all the HTML into the new div
$('#addRow_'+btnId).prop("disabled", true);//Disables the add button once clicked.
});
//Remove the text filed from the list and resets the error number
$(document).on('click', '.delRow', function () {
var //btnId = $(this).data("bid").match(/\d+/),//Breaks the number from the ID using .match
maxNoList = $('input[class="addRow"]').length,
errNoList = maxNoList - 1;
alert(errNoList);
//btnId = btnId - 1; //Calculates the ID number of the previous button
$('#addRow_'+errNoList).prop('disabled',false);// Enables the previous add button
$('#stValue').val(errNoList); //Set the value of stValue when removing the text filed
//So the error numbers will be generated accordingly when Add is clicked again.
$(this).parent().remove(); //Remove the text row from the list.
});
});
//HTML function which will be called by the button click event for the add button
function copy() {
var stNum = document.getElementById("stValue"),
genNum = (document.getElementById("stValue").value - 1)+2;
stNum.value = genNum;
// language=HTML
return '<input class="errorCount" size="1" value="'+genNum+'" style="margin-left: 2%" readonly/>\n' +
'<select class="errorName" style="margin-left: 6%">\n' +
'<option selected disabled>----- Select Error -----</option>\n' +
'</select>\n' +
'<input type="button" class="addRow" id="addRow_'+genNum+'" data-bid="addRow_'+genNum+'" value="Add" />\n' +
'<input type="button" class="delRow" id="delRow_'+genNum+'" data-bid="delRow_'+genNum+'" value="Delete"/><br />'
}
<div id="jType-container">
<div id="error-Add-Container">
<div id="error-Column-Headings">
Error Number<span style="margin-left: 8%">Error Name</span>
</div>
<div class="error-Column">
<input class="errorCount" size="1" value="1" style="margin-left: 2%"/>
<input type="hidden" value="1" id="stValue"/>
<select class="errorName" style="margin-left: 6%">
<option selected disabled>----- Select Error -----</option>
</select>
<input type="button" data-bid="addRow_1" id="addRow_1" class="addRow" value="Add"/>
</div>
</div>
</div>
$(".errorCount").each(function(index, _this) {
$(this).val(index + 1);
});