问题: A页面通过<iframe>引入B页面 ,现在想通过A页面提交表单时验证B页面的文本框非空;如何实现!
求实例:

解决方案 »

  1.   

    A页面验证函数里可以这么获取Bwindows.frame['b'].document.getElementById('#B页面某个标签的ID')
      

  2.   

    不好意思,更正一下:windows.frame['b'].改为:windows.frames['b'].例子如下:
    a.htm为:<script>
    window.onload=function(){
    document.getElementById('bt').onclick=function(){alert(window.frames['b'].document.getElementById('b').value);}
    }
    </script>
    <iframe src="b.htm" id="b" name="b"></iframe>
    <input type="button" id="bt" value="tijiao">b.htm为:
    <input type="text" value="bbbccc" id="b">结果:在a.htm里点击提交按钮;警告b.htm里的id为B的VALUE值BBBCCC
      

  3.   

    如果要判断非空就改改a.htm就可以了,如下:
    <script>
    window.onload=function(){
    document.getElementById('bt').onclick=function(){
        if(window.frames['b'].document.getElementById('b').value=="")
    {alert('b.htm里id为b的value值为空!');} 
            else
                {alert('非空');}
    }
    }
    </script>
    <iframe src="b.htm" id="b" name="b"></iframe>
    <input type="button" id="bt" value="tijiao">//在框架里的文本框里面输入值试试!
      

  4.   

     var b= window.frames['ad_cn1'].document.getElementById('txt1').value;为什么不可以进行赋值判断啊,当TXT1为空的时候正常,当有值的时候
    报var b= window.frames['ad_cn1'].document.getElementById('txt1').value;不支持此属性或方法;有解决办法吗
      

  5.   

    报缺少对象;var tt=window.frames['ad_cn1'].document.getElementById('txt1').value; if(tt==null||tt==""){
      

  6.   

    top就行了!
    top.document.getElementById("txtInput01") 就能获取父页面元素 反过来也一样 ls几位已经给出答案了
      

  7.   

    那个TXT1是个上传类型;
    <input  type="file" name="txt1" id="txt1">
    没值的时候可以正常判断,当上传有值时,报window.frames['ad_cn1'].document.getElementById('txt1').value缺少对象;
      

  8.   

    是这样的,JS里先验证B页面的非空,然后还有本页面的验证;
    结果现在是B页面验证的同时也验证了A页面;
    想在验证B不成功就返回FALSE;不进行A页面验证;如果做...
      

  9.   

    代码说话:看清楚了B没有做选择就直接返回!而不继续验证下面A部分的!
    <script>
    function check(){
        if(window.frames['b'].document.getElementById('txt').value=="")
    {
    alert('b.htm里id为b的value值为空!');
             return false;//这个很关键,这个失败了也就不继续向下运行代码了!
    }

        //以下部分这里放其他验证代码
       }
    </script>
    <form name="frm" action="" onsubmit="return check()">
    <iframe src="b.htm" id="b" name="b"></iframe>
    <input type="submit" id="bt" value="tijiao">
    </form>
      

  10.   

    我是这样来验证的,但是,一但上传文件有值后,就报运行时间错误,缺少对象window.frames['ad_cn1'].document.getElementById('txt1').value==""这句它不认识了又。
      

  11.   

    非常感谢falizixun2 不是它的问题了。是因为上传成功后返回的是文本
    那个上传它找不到所以报错了;