我试图动态添加行。似乎除了复选框之外,所有数据都在服务器端保存。
<td rowspan="2" class="text-center">
<input name="F_02_0080_2" id="F_02_0080_2" class="" type="checkbox">
</td>
<td rowspan="2" class="text-center">
<input name="F_02_0090_2" id="F_02_0090_2" class="" type="checkbox">
</td>
这是添加动态复选框时的结构。 这是我的javascript(删除了不需要的函数,所以如果找不到func的定义,请忽略。):
ihtx.prvl_unlisted_securities_0101_h250527 = {
createnew:function(parent_tr){
var _this = ihtx.prvl_unlisted_securities_0101_h250527;
var clonned_tr = parent_tr.clone()
_this.set_after(parent_tr, clonned_tr);
_this.update_row_attributes(clonned_tr, parent_tr.index()/2);
_this.set_blank_row(clonned_tr);
$(clonned_tr).find("td:eq(1)").html(element);
$(clonned_tr).nextAll(".sortable-ihtx").each(function(i, elm){
var rowindex = (clonned_tr.index()/2 +i);
_this.update_row_attributes($(this), rowindex);
_this.update_row_attributes($(this).next(), rowindex);
});
},
set_after:function(row1, row2){
// One row is a combination of two `tr`s
// only first tr have the checkboxes
var last_row = row1[1];
$(last_row).after(row2);
},
update_row_attributes:function(oldrow, index_to_set){
var _this = ihtx.prvl_unlisted_securities_0101_h250527;
$(oldrow).children().find("input[type='text'], textarea, input[type='checkbox']").each(function(i, elm){
if($(this).is("[type='text']"))$(this).inputmask();
if(isFloat(index_to_set))index_to_set =index_to_set - 0.5;
_this.set_elm_attributes($(this), index_to_set);
});
_this.update_display_order(oldrow, index_to_set);
},
set_elm_attributes:function(elm, oldindex){
var _this = ihtx.prvl_unlisted_securities_0101_h250527;
var attributes = elm.attr();
$.each(attributes, function(key, val){
if($.inArray(key, ["name", "id", "class"]) != -1){
$newattr = _this.get_new_attribute_name(key, val, oldindex);
if(key == "class"){
$class = elm.attr("class")
$newattr = $class.replace(elm.attr("name"), _this.get_new_attribute_name("class", elm.attr("name"), oldindex));
}
elm.attr(key, $newattr);
}
});
}
},
set_blank_row:function(row){
$(row).children().find("input[type='text'], textarea, input[type='checkbox']").each(function(){
$(this).val("");
if($(this).is(':checkbox')){
$(this).removeAttr("checked");
}
});
},
答案 0 :(得分:1)
根据@Barmar的评论,我应该做以下更改:
set_blank_row:function(row){
$(row).children().find("input[type='text'], textarea,input[type='checkbox']").each(function(){
$(this).val("");
if($(this).is(':checkbox')){
$(this).removeAttr("checked");
var clicked = $(this).attr('checked');
if(clicked){
$(this).attr('value', 'on');
}else{
$(this).removeAttr('value');
}
}
});
}