| 如何检测选中的checkbox的个数 |
| [ 来源:ITWENKU 时间:2007-4-17 10:15:14 | 浏览:316人次
] |
| |
|
我用do while not rs.eof循环生成了新闻之前的checkbox。如何检测被选中的checkbox个数?当没有新闻被选中时,又怎么用msgbox提示不能进行下一步操作?(我用VBSCRIPT)
<script language="vbscript"> function checkme() Dim inCount Dim strValue inCount = 0 For Each ob In chk if ob.checked then inCount = inCount + 1 If strValue = "" Then strValue = ob.value Else strValue = strValue & "," & ob.value End If End If Next If inCount = 0 Then MsgBox "No Checked" Else MsgBox inCount & " Checked, Value=" & strValue End if end function </script><BODY> <INPUT name="chk" type="checkbox" value="北京" checked>北京 <INPUT name="chk" type="checkbox" value="上海">上海 <INPUT name="chk" type="checkbox" value="广州">广州 <INPUT name="chk" type="checkbox" value="深圳">深圳 <INPUT type="button" value="check" onclick="checkme()">
function SelectChk() { var Menuid,n=0; var strid,strurl; var nn = self.document.all.item("Menu") for (j=0;j<nn.length;j++) { if (self.document.all.item("Menu",j).checked) { n = n + 1; s=true; Menuid = self.document.all.item("Menu",j).id+""; } } if(n==0) {alert("ddd"); return false; } else {} }
星星火炬,你给出的答案单独可以用。但是我加在我所写的里面就没有MSGBOX弹出,不知道怎么回事。代码如下: <body> <script language="vbscript"> function checkme() cc=0 for each ob in checkboxDEL if ob.checked then cc=cc+1 end if next if cc=0 then msgbox "no selected" else msgbox cc&"selected" end if end function </script>
<% set conn=server.CreateObject("adodb.connection") application.Lock() conn.open "webdata","sa","111" set rs=server.CreateObject("adodb.recordset") mysql="select num as 编号,title as 标题,author as 作者,time as 发表时间 from news order by num desc" rs.open mysql,conn,2,2 %> <form name="form1" id="form1" action="" method="post"> <table border="1" width="84%" align="center"> <tr align="center"> <td><%="请选择"%></td> <td><%="<b>"&rs(0).name%></td> <td><%="<b>"&rs(1).name%></td> <td><%="<b>"&rs(2).name%></td> <td><%="<b>"&rs(3).name%></td> </tr>
<% rs.movefirst() do while not rs.eof %> <tr align="center"> <td><input type="checkbox" id="checkboxDel" name="checkboxDel" value="<%=rs(0)%>" /></td> <td><%=rs(0)%></td> <td><%=rs(1)%></td> <td><%=rs(2)%></td> <td><%=rs(3)%></td> </tr> <% rs.movenext() loop %> </table> <input name="buttonDel" type="submit" id="buttonDel" value="删除" onclick="checkme()" /> <input name="buttonAdd" type="button" id="buttonAdd" value="添加" /> <input name="buttonExit" type="button" id="buttonExit" value="退出" /> </form> <% application.UnLock() conn.close() set conn=nothing %> </body>
<script language="vbscript"> Function checkme() checkme =true Dim inCount Dim strValue inCount = 0 For Each ob In form1.chk if ob.checked then inCount = inCount + 1 If strValue = "" Then strValue = ob.value Else strValue = strValue & "," & ob.value End If End If Next If inCount = 0 Then MsgBox "No Checked" checkme =false Exit Function Else MsgBox inCount & " Checked, Value=" & strValue Submit() End if end Function </script> <BODY> <form name="form1" action="dd.asp" method="post"> <INPUT name="chk" type="checkbox" value="北京" checked>北京 <INPUT name="chk" type="checkbox" value="上海">上海 <INPUT name="chk" type="checkbox" value="广州">广州 <INPUT name="chk" type="checkbox" value="深圳">深圳 <INPUT type="submit" value="check" onclick="checkme"> </form>
星星火炬,现在可以了。但是没搞懂这中间是什么原因,为什么我的没有MSGBOX弹出?你的修改是怎么个意思?能讲讲吗,不好意思,我刚学的
For Each ob In form1.chk '如果有表单域的话,要写出来
If inCount = 0 Then MsgBox "No Checked" checkme =false Exit Function '退出函数 Else MsgBox inCount & " Checked, Value=" & strValue Submit() '执行提交 End if
懂了,呵呵,谢谢
|
|
 |
推荐文章 |
|