firefox中设置attr无效
我想实现选择一个复选框时,其他相关的复选框也选中或者不选。 chk_Click方法在IE中有效,在firefox中第一次选中时有效,以后设置无效。
XML/HTML code?051525354555657585960616263646566676869 <!--#include virtual="/conn.asp"--><!--#include virtual="/include/CommFunc.asp"--><!--#include virtual="/include/ChkSession.asp"--><!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> <meta http-equiv="Content-Type" content="text/html; charset=gbk" /> <title>内容</title> <link rel="stylesheet" href="css/layout.css" type="text/css"> <link rel="stylesheet" href="css/reset.css" type="text/css"> <link rel="stylesheet" href="css/reset.css" type="text/css"> <link rel="stylesheet" type="text/css" href="/admin/css/css.css"/> <script type="text/javascript" src="/js/jquery-1.9.1.js"></script> <script type="text/javascript"> function chk_Click(src) { if(src.id.length==5) { alert(src.checked); if (src.checked==true) $("#tbMenuList input[id^="+ src.id +"]").attr("checked",'true'); else $("#tbMenuList input[id^="+ src.id +"]").removeAttr("checked"); } } </script> </head> <body> <div id="content_top"> <div class="nav"> <div class="nav_back nav_son"><a href="#">后退</a></div> <div class="nav_forward nav_son"><a href="#">前进</a></div> <div class="nav_refresh nav_son"><a href="#">刷新</a></div> <div class="nav_exit nav_son"><a href="#">退出</a></ddiv> </div> </div> <div class="clearfloat"></div> <div id="content_main"> <table width="58%" cellpadding="10" cellspacing="0" class="news_list" style="width:200px;" id="tbMenuList"> <tr> <th height="30" class="tdLeft">选择</th> <th class="tdRight">菜单名称</th> </tr> <% dim sql,rs sql="select * from menu order by OrderNumber" set rs=Server.CreateObject("adodb.recordset") rs.open sql,conn,1,1 do while not rs.eof %> <tr> <td height="25" class="tdLeft"><input name="chk<%=rs("MenuID")%>" id="chk<%=rs("MenuID")%>" type="checkbox" value="<%=rs("MenuID")%>" onclick="chk_Click(this);"/></td> <td class="tdRight"><% if len(rs("MenuID"))=2 then Response.write rs("MenuName") else Response.write " "& rs("MenuName") end if %></td> </tr> <% rs.movenext loop %> </table> </div> </body> </html>
可以换种方法啊
你不就是做选中和不选中嘛
$("#tbMenuList input[id^="+ src.id +"]").attr("checked",'false');
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>test</title> <script src="http:-//ajax.googleapis-.-com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script type="text/javascript"> function chk1_onclick(srv) { $("#chk2").prop("checked",srv.checked); $("#chk2").attr("checked",srv.checked); } </script> </head> <body> <input name="chk1" id="chk1" type="checkbox" value="1" onclick="chk1_onclick(this);"/> <input name="chk2" id="chk2" type="checkbox" value="2" /> </body> </html>