如何评价奇葩说:js问题 提示window.form.chk为空或不是对象

来源:百度文库 编辑:中科新闻网 时间:2024/05/05 15:57:45
附上代码 大虾们看看是什么问题

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<script language="javascript">
function chke(chk)
{
var chk=chk;
if (form.chk.checked==true)
{alert(form+'的'+chk+'被选中');}
}
</script>
</head>

<body>
<form action="text1" method="post" name="form">

<input type="checkbox" name="chk1" onClick="chke('chk1')" >

<input type="checkbox" name="chk2" onClick="chke('chk2')" >

<input type="checkbox" name="chk3" onClick="chke('chk3')" >

<input type="checkbox" name="chk4" onClick="chke('chk4')" >

</form>
</body>
</html>
大虾们 其实我着是用动态的来做的
但是怎么样也 做不出来
给看看吧
完全的代码
——————————————————————
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>

</head>

<body><script language="javascript">
function chke(obj)
{
if (obj.checked==true)
{alert(obj+'被选中');}
}
</script>
<form action="text1" method="post" name="form">
<%
for i=1 to 4

%>

<input type="checkbox" id="chk<%=i%>" onClick="chke(this)" >

<%next%></form>
</body>
</html>

刚开始弄得没有弹出 - - 改了一下 用id
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<script language="javascript">
function chke(chk)
{
if (document.getElementById(chk).checked==true)
alert('您选中的是第'+chk+'个');
}
</script>
<form action="text1" method="post" name="form">
<%
for i=1 to 4
%>
<input name="chk" type="checkbox" id="chk<%=i%>" onClick="chke('chk<%=i%>')">
<%next%>
</form>
</body>
</html>

<script language="javascript">
function chke(obj)
{

if (obj.checked==true)
{alert(form+'的'+obj+'被选中');}
}
</script>

<form action="text1" method="post" id="form">

<input type="checkbox" id="chk1" onClick="chke(this)" NAME="chk1">

<input type="checkbox" id="Checkbox1" onClick="chke(this)" NAME="Checkbox1">

<input type="checkbox" id="Checkbox2" onClick="chke(this)" NAME="Checkbox2">

<input type="checkbox" id="Checkbox3" onClick="chke(this)" NAME="Checkbox3">

<input type="checkbox" id="Checkbox4" onClick="chke(this)" NAME="Checkbox4">
</form>
试试