通过JS功能在中继器中启用文本框
Enable textbox inside Repeater through JS function
我的文本框(asp.net)位于中继器详细信息部分的DIV和面板内(切换)如何访问java脚本函数中的文本框,使其在单击同一面板中的链接按钮时启用。
<div id='d<%# DataBinder.Eval(Container, "ItemIndex") %>' class="details">
<asp:Panel ID="Panel2" runat="server" Height="195px" BackColor="gray" Font-Bold="False" ForeColor="Maroon">
<br />
<asp:Label ID="Label1" runat="server" Text="LicenseID"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# DataBinder.Eval (Container.DataItem,"LicenseID") %>' Enabled="False" BackColor="Gray" BorderStyle="None"></asp:TextBox>
我尝试过这种方式,但显示错误
<script type="text/javascript">
function MyJSFunction() {
var tet = document.getElementById("<%=TextBox1.ClientID %>");
}
</script>
但是显示以下错误消息。
BC30451:"文本框 1"未声明
由于其保护级别,它可能无法访问。
编辑 这是我在 vb.net 的代码。但是转换为js函数我发现了错误
If e.CommandName = "edit" Then
DirectCast(e.Item.FindControl("TextBox2"), TextBox).Enabled = True
DirectCast(e.Item.FindControl("Textbox2"), TextBox).BorderStyle =BorderStyle.NotSet
DirectCast(e.Item.FindControl("Textbox2"), TextBox).BackColor = Drawing.Color.White
end if
这是因为在中继器中,您的ID变得yourRepeaterID_TextBox1_Sequence使用 Javascript 来处理所有输入。像这样:
<script>
function MyJSFunction() {
var tb = document.getElementsByTagName('INPUT');
for (var i = 0; i < tb.length; i++) {
if (tb[i].type != "text") { continue; } // this is not TextBox
// do whatever
}
}
</script>
将 jquery 与选择器一起使用,如下所示:
var textBox = $(".details input[type='text'][id*='TextBox1']");
问候乌鲁斯
相关文章:
- 使用javascript Without Ajax/Jquery在特定行中启用文本框
- 单击每个表格行中的复选框时启用文本框
- 禁用基于下拉列表选择 asp.net JavaScript 启用文本框
- 根据下拉列表中的选定值启用文本框
- 重新启用文本选择(Opera、webkit等)
- 根据输入启用文本框
- 通过JS功能在中继器中启用文本框
- 启用文本框选中复选框数组
- 如何在特定行中启用文本框
- 单选按钮未启用文本框
- 启用文本输入
- 与disableSelection功能相反,后者用于为特定HTML元素启用文本选择
- ASP.NET MVC Checboxes禁用/启用文本框
- 无法使用mootools启用文本框
- 当下拉框中的值被选中时,启用文本框
- 选中单选按钮导致在asp.net中启用文本框
- 如何在ChromeOS应用程序窗口中启用文本选择
- 禁用/启用文本框,单击单选按钮
- 使用javascript启用文本框
- 启用文本选择javascript