<head runat="server"> <title></title> <script> function clickinfo(obj, itemid) { var doc = document.getElementById(itemid); if (doc.checked) { doc.checked = false;
f(); } else { doc.checked = true;
f(); } } function f() { var che = document.getElementsByName("cheusername"); var name = ""; for (var i = 0; i < che.length; i++) { if (che[i].checked) { name += che[i].value+" "; } } document.getElementById("txtName").value = name; } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:DropDownList runat="server" ID="ddl"> </asp:DropDownList> <asp:TextBox ID="txtName" runat="server"></asp:TextBox> <table style="width: 100%;"> <tr> <td> </td> <td> </td> <td> </td> </tr> <asp:Repeater ID="rep" runat="server"> <ItemTemplate> <tr onclick='clickinfo(this,<%#eval("itemid") %>)' > <td> <input type="checkbox" id='<%#Eval("itemid") %>' name="cheusername" /> </td> <td> 姓名 </td> <td> </td> </tr> </ItemTemplate> </asp:Repeater> </table> </div> </form> </body> </html>
现在txtName的值在Dropdownlist更改后复选框选择时 txtName之前的内容就为空了 咋整~~~ 想不出来
你是DropDownList还是checkbox啊?checkbox的ID是唯一的吧?DropDownList可以把值写到文本框中哦!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script type="text/javascript"> function btnClick() { var doc = document.getElementById("id"); var names = ""; for (var i = 0; i < doc.length; i++) { names = names + doc[i].innerText+","; } document.getElementById("msg").value = names; } </script> </head> <body> <select id="id" onclick="btnClick()"> <option value="1">你好</option> <option value="2">他好</option> <option value="3">大家好</option> </select> <input type="text" id="msg" /> </body> </html>
改了一下 问题你看看~~
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>的Id是什么?
txtName 啊
@锈戒: 是么,你去生成的页面找找
@羽商宫: txtName 这就是个显示的地方 ~~跟解决方法没多大关系~