Javascript Jquery在HTML表中添加单元格我想我设置它显示无,因为这些是ID?MVC
我实际上是在向HTML表中添加id,而不是使用它们来保存。 但我不想表现出来 这是我的jquery,用于将单元格添加到表中Javascript Jquery在HTML表中添加单元格我想我设置它显示无,因为这些是ID?MVC,javascript,c#,jquery,html,asp.net-mvc,Javascript,C#,Jquery,Html,Asp.net Mvc,我实际上是在向HTML表中添加id,而不是使用它们来保存。 但我不想表现出来 这是我的jquery,用于将单元格添加到表中 $("body").on("click", "#btnAdd", function () { //Reference the Name and Country TextBoxes. var txtName = $("#txtFamilyName"); // var txtCountry = $("#t
$("body").on("click", "#btnAdd", function () {
//Reference the Name and Country TextBoxes.
var txtName = $("#txtFamilyName");
// var txtCountry = $("#txtCountry");
//Get the reference of the Table's TBODY element.
var tBody = $("#tblCustomers > TBODY")[0];
//Add Row.
var row = tBody.insertRow(-1);
//Add Name cell.
var cell = $(row.insertCell(-1));
cell.html($('#ddlregion').find('option:selected').text());
var cell = $(row.insertCell(-1));
cell.html($('#ddlcityy').find('option:selected').text());
var cell = $(row.insertCell(-1));
cell.html(ddlcityy.value);
var cell = $(row.insertCell(-1));
cell.html(ddltribe.value);
//Add Button cell.
cell = $(row.insertCell(-1));
var btnRemove = $("<input />");
btnRemove.attr("type", "button");
btnRemove.attr("onclick", "Remove(this);");
btnRemove.val("Remove");
cell.append(btnRemove);
});
他们都在工作,但只为一个细胞
让我看看我换成什么
var cell = $(row.insertCell(-1));
cell.html(ddlcityy.value);
cell.setAttribute("hidden", true);
var cell = $(row.insertCell(-1));
cell.html(ddltribe.value);
cell.setAttribute("hidden", true);
“Cityid”是3,“Tribeid”是1,每次只隐藏部落id而不是城市id。
我甚至将它们的变量名从cell改为cell1,但结果是一样的
为什么只隐藏部落id?只需通过设置为
none
来隐藏该行,就像document.getElementById(yourCell.style.display='none'
添加后如何设置其style属性您的cell
id是正确的吗?将单元格iddocument.getElementById(yourCell.style.display==“none”
传递到cell.html(ddlbreage.value)之后代码>不,我没有在我的查询中添加这个cell.setAttribute(“hidden”,true)代码>或'cell.style.display='none'`只需通过设置为none
来隐藏该行,就像document.getElementById(yourCell.style.display==“none”
添加后如何设置其样式属性您有cell
id权限?将单元格iddocument.getElementById(yourCell.style.display==“none”
传递到cell.html(ddlbreage.value)之后代码>不,我没有在我的查询中添加这个cell.setAttribute(“hidden”,true)代码>或'cell.style.display='none'`
var cell = $(row.insertCell(-1));
cell.html(ddlcityy.value);
cell.setAttribute("hidden", true);
var cell = $(row.insertCell(-1));
cell.html(ddltribe.value);
cell.setAttribute("hidden", true);