我想知道如何控制行的添加。如果下拉列表中没有选定项,则不应添加行。这是代码。
var journalSizeReportingTmpl = 'journalSizeReportingTmpl';
jQuery.template(journalSizeReportingTmpl,
jQuery("#journalSizeReportingTmpl"));
jQuery(document).ready(function(){
jQuery(".journalRows").on("change","select.journalMnemonicsDropdown",function(e){
disableFields(jQuery(this));
});
});
function newJournalRow() {
var id = jQuery('#rowCount').attr("value");
var data = [{fileId: id}];
jQuery.tmpl(journalSizeReportingTmpl, data).insertBefore("tr.lastRow");
id = ++id;
jQuery('#rowCount').attr("value",id);
}
//
function disableFields(element){
var elementVal = element.attr("value");
var name = element.attr("name");
var id = name.substring(name.indexOf("(")+1,name.indexOf(")"));
if(elementVal== "All"){
jQuery( "input[name='startVolume("+id+")']" ).attr("disabled", "disabled");
jQuery( "input[name='startIssue("+id+")']" ).attr("disabled", "disabled");
jQuery( "input[name='endVolume("+id+")']" ).attr("disabled", "disabled");
jQuery( "input[name='endIssue("+id+")']" ).attr("disabled", "disabled");
} else {
jQuery( "input[name='startVolume("+id+")']" ).removeAttr("disabled");
jQuery( "input[name='startIssue("+id+")']" ).removeAttr("disabled");
jQuery( "input[name='endVolume("+id+")']" ).removeAttr("disabled");
jQuery( "input[name='endIssue("+id+")']" ).removeAttr("disabled");
newJournalRow();
}