使用JQuery隐藏动态创建的标签

时间:2017-08-28 05:35:57

标签: javascript jquery dynamic

我正在动态创建一些文本框和标签,并且我试图通过JQuery隐藏/显示它们,但无法使JQuery正常工作。我做错了什么?

这是背后的代码:

TableCell td4 = new TableCell();

Label l2 = new Label();

l2.ID = "lbSell" + dp.dSellAutoID.ToString();
l2.Text = Math.Round(Convert.ToDecimal(dp.dSellPrice), 2).ToString();
l2.Visible = false;
td4.Controls.Add(l2);

TextBox tb1 = new TextBox();

tb1.ID = "tbSell" + dp.dSellAutoID.ToString();
tb1.Width = 50;
tb1.Text = Math.Round(Convert.ToDecimal(dp.dSellPrice), 2).ToString();
td4.Controls.Add(tb1);
tr.Cells.Add(td4);

这是JS:

function editRow(rowID) {
    //alert(rowID);
    $('#' + 'lbSell' + rowID).show();
    $('#' + 'tbSell' + rowID).hide();
}

1 个答案:

答案 0 :(得分:1)

您使用母版页吗?在这种情况下,ID会在呈现页面时更改。要防止它,您可以将ClientIDMode="Static"添加到页面指令

<%@ Page Title="" Language="C#" ClientIDMode="Static" MasterPageFile="~/epinet.master" %>

请参阅:https://stackoverflow.com/a/5494142/5746368