首页 新闻 会员 周边

Js DropdownList 复选框值 叠加

0
悬赏园豆:20 [已解决问题] 解决于 2015-07-17 08:49
<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> &nbsp; </td> <td> &nbsp; </td> <td> &nbsp; </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> &nbsp; </td> </tr> </ItemTemplate> </asp:Repeater> </table> </div> </form> </body> </html>

  现在txtName的值在Dropdownlist更改后复选框选择时  txtName之前的内容就为空了 咋整~~~  想不出来

SSS.M.AAA的主页 SSS.M.AAA | 初学一级 | 园豆:5
提问于:2015-04-08 12:34
< >
分享
最佳答案
0

你是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>
收获园豆:20
success365 | 菜鸟二级 |园豆:226 | 2015-04-08 13:18

    改了一下  问题你看看~~

SSS.M.AAA | 园豆:5 (初学一级) | 2015-04-08 13:41
其他回答(1)
0

<asp:TextBox ID="txtName" runat="server"></asp:TextBox>的Id是什么?

羽商宫 | 园豆:2490 (老鸟四级) | 2015-04-08 13:56

txtName  啊

支持(0) 反对(0) SSS.M.AAA | 园豆:5 (初学一级) | 2015-04-08 14:06

@锈戒: 是么,你去生成的页面找找

支持(0) 反对(0) 羽商宫 | 园豆:2490 (老鸟四级) | 2015-04-08 14:10

@羽商宫:      txtName  这就是个显示的地方  ~~跟解决方法没多大关系~

支持(0) 反对(0) SSS.M.AAA | 园豆:5 (初学一级) | 2015-04-08 14:17
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册