日期:2014-05-16  浏览次数:20351 次

求教:在textbox中获取checkbox值
<asp:TextBox ID="txtPersons" runat="server" CssClass="textarea wh380 required "></asp:TextBox>
<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
  <ItemTemplate>
  <ul>
  <li>
  <%#Eval("DepId")%>
  <%#Eval("Name")%></li></ul>
  <asp:Repeater ID="Repeater2" runat="server">
  <ItemTemplate>
  <asp:CheckBox ID="cb" runat="server" Text='<%#Eval("RealName")%>' />
  <asp:HiddenField ID="hidId" Value='<%#Eval("UserId")%>' runat="server" />  
  </ItemTemplate>
  </asp:Repeater>
  </ItemTemplate>
  </asp:Repeater>
如何将选中的值赋值到asp:TextBox 中?
我用.net提交方法传参实现不了,一提交就会导致别的textbox值清空,只能求教客户端代码了,又写不好,哪位帮忙写下,谢谢了!

------解决方案--------------------
JScript code
            function setText(ID, v,checked) {
                var txt = document.getElementById(ID), vs = txt.value;
                if (checked) vs += (vs == '' ? ',' : '') + v + ',';
                else vs = vs.replace(',' + v + ',', ',');
                txt.value = vs;
            }

------解决方案--------------------
var cks= $(input[id^='checkbox的ID']) 这里是多个checkbox
做个循环 for(var i=0;i<cks.length;i++)
做个判断 if($(cks[i]).attr("checked")==true)
再赋值给textbox就可以了