因为我必须取iframe中的checkbox的Value值以后才能提交,现在的问题是无法取得iframe中的checkbox的值
解决方案 »
- 关于onchange事件的疑惑
- $.trim $("#CommentText")
- 纳斯达克上市公司 Avocent 招聘 Web Development Software Engineer,偏JS
- 正则表达式匹配网址的一段js程序,麻烦大家帮忙修改一下怎样匹配的好
- submit提交后不刷新当前页面
- ajax 实现级联菜单的形式,为什么总执行最后一行代码?
- 点击表格某行的图片,怎么得到该行某一列的值
- 输入框如何通过脚本语言来控制读写
- 在Javascript中实现循环?急
- 请教:在Javascript里面怎么关闭所有的图层
- 网页刷新
- 急!!!怎么用javascript得到本地(客户端)的所有网卡的IP地址?
<iframe id=myiframe src="about:<input type=checkbox name=mycheckbox value=mycheckbox>"></iframe>
<input type=button value=submit onclick="alert(myiframe.mycheckbox.checked);form1.submit()">
</form>
页面会出现myiframe.mycheckbox.checked不是对象的错误
我的表单名为FrmList
Iframe的ID为List
checkbox的名字为List
对了,checkbox不止一个,有很多,是同名不同值的
<iframe id=List
src="about:<input type=checkbox name=mycheckbox value=1><input type=checkbox name=mycheckbox value=2><input type=checkbox name=mycheckbox value=3>"></iframe>
<input type=button value=submit onclick="mysubmit()">
</form>
<script>
function mysubmit()
{
for(i=0;i<List.mycheckbox.length;i++)
{
alert(List.mycheckbox[i].checked);
alert(List.mycheckbox[i].value);
}
FrmList.submit();
}
</script>
<form name="frmList" method="post" action="Customer_Del.asp">
<table width="100%" border="0" cellspacing="0" cellpadding="1">
<tr>
<td valign="middle">
<div align="right"><a href="#"><img src="images/Customer_Add.gif" width="87" height="18" border="0" onClick="MM_openBrWindow('Customer_Add.asp','','width=400,height=335,resizable=no ,help=yes')"></a>
<input type="image" border="0" name="imageField" src="images/Customer_Del.gif" width="87" height="18" onclick="mysubmit()">
<script>
function mysubmit()
{
for(i=0;i<List.mycheckbox.length;i++)
{
alert(List.mycheckbox[i].checked);
alert(List.mycheckbox[i].value);
}
FrmList.submit();
}
</script>
</div>
</td>
</tr>
</table>
<iframe ID=List Name=List src="Customer_Files.asp" Width="100%" height="180px" scrolling="Auto" FrameBorder="1"></iframe>
</form>
如有不止一个则用document.all[checkboxname]取得,我写了一个函数你用用看吧!如下
//--- 方法名: getCheckedString(AFormName,AChkName,ADivStr)
//--- 功能: 取得单选框中的值
//--- 返回: 选中单选框的值,如没有选中返回"";
//--- AFormName: 所在的Form名
//--- AChkName: CheckBox列表的名
//--- ADivStr: 分割字符串
//--- 创建日期: 2002-04-10 最近更新日期: 2002-04-10
//--- 创建程序员: xg_delayth 最近更新程序员: xg_delayth
function getCheckedString(AFormName,AChkName,ADivStr){
var collection,i,tmpValue="";
try{
collection=document.all[AChkName];
if (1<collection.length){
for (i=0;i<collection.length;i++){
if (true==collection[i].checked && collection[i].value!=""){
tmpValue=tmpValue+collection[i].value+ADivStr;
}
}
if (""!=tmpValue) return tmpValue.substring(0,tmpValue.lastIndexOf(ADivStr));
else return "";
} else{
if (eval(AFormName+"."+AChkName+".checked")){
return eval(AFormName+"."+AChkName+".value");
} else{
return "";
}
}
} catch(e){
return "";
}
}
<table width="100%" border="0" cellspacing="0" cellpadding="1">
<tr>
<td valign="middle">
<div align="right"><a href="#"><img src="images/Customer_Add.gif" width="87" height="18" border="0" onClick="MM_openBrWindow('Customer_Add.asp','','width=400,height=335,resizable=no ,help=yes')"></a>
<input type="image" border="0" name="imageField" src="images/Customer_Del.gif" width="87" height="18" onclick="mysubmit()">
<script>
function mysubmit()
{
for(i=0;i<List.frmList.mycheckbox.length;i++)//frmList为iframe中form名
{
alert(List.frmList.mycheckbox[i].checked);
alert(List.frmList.mycheckbox[i].value);
}
if((i==0)&&(List.frmList.mycheckbox!=null))//当只有一个checkbox时
{
alert(List.frmList.mycheckbox.checked);
alert(List.frmList.mycheckbox.value);
}
FrmList.submit();
}
</script>
</div>
</td>
</tr>
</table>
<iframe ID=List Name=List src="Customer_Files.asp" Width="100%" height="180px" scrolling="Auto" FrameBorder="1"></iframe>
</form>