Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将.Net Repeater与jquery一起使用_Jquery_.net_Repeater - Fatal编程技术网

将.Net Repeater与jquery一起使用

将.Net Repeater与jquery一起使用,jquery,.net,repeater,Jquery,.net,Repeater,我有一个中继器ASP.Net <asp:Repeater ID="rep" runat="server"> <ItemTemplate> <asp:TextBox runat="server" ID="txt"></asp:TextBox> <asp:CheckBox runat="server" ID="cb" /> </ItemTemplate> 如果我使用jQuery单击复选框,我想在文本框中写入文本。这可能吗?如

我有一个中继器ASP.Net

<asp:Repeater ID="rep" runat="server">
<ItemTemplate>
<asp:TextBox runat="server" ID="txt"></asp:TextBox>
<asp:CheckBox runat="server" ID="cb" />
</ItemTemplate>


如果我使用jQuery单击复选框,我想在文本框中写入文本。这可能吗?如何可能。

是的,是的。一种可能性是服务器的方法:

在复选框的服务器中的Load事件上,可以执行以下操作:

void checkBox_Load(object sender, EventArgs e)
{
     CheckBox chk = (CheckBox) sender;
     TextBox txt = (TextBox) chk.Parent.FindControl("txt");
     chk.Attributes.Add("onclick",
                          string.Format("$(\"#{0}\").val('{1}');", txt.ClientID, "newValue");
}

编辑:jQuery选择器中缺少。您必须发布html输出以获得工作代码,但它是这样的:

$(function(){
    $('#<%=rep.ClientID  %> input[type="checkbox"]').each(function(){
        $(this).change(function(){
            $(this).siblings('input[type="text"]').first().val("clicked");
        });
    });
});

使用jQuery,您可以使用ID选择器选择您指定的ID=txt的DOM元素

然后可以更新这些元素的.text属性

这样的东西应该以最简单的方式工作:

$("#txt").text("some new text");

我建议只使用CSS类并使用它来标识文本框:

<asp:Repeater ID="rep" runat="server">
  <ItemTemplate>
    <asp:TextBox runat="server" ID="txt"></asp:TextBox>
    <asp:CheckBox runat="server" ID="cb" CssClass="repCheck" />
  </ItemTemplate>

在中继器中,实际id属性将有一个自动生成的值。如果我有多个文本框。。。我想更改每个?@RonakBhatt的值,这听起来像是一个单独的问题:@RonakBhatt-注释不是用于对话的,但是您可以简单地从复选框更改处理程序中访问多个输入。如果它们不同,可以使用class.thanx@rechard…缩小选择器的范围。。。。实际上,我是在假设同样的结果。。但是我对此没有信心。。
$('.repCheck').change(function(){
    // via Andre
    $(this).siblings('input[type="text"]').first().val("clicked");
});