Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 另一帧上的复选框计数_Javascript_Html - Fatal编程技术网

Javascript 另一帧上的复选框计数

Javascript 另一帧上的复选框计数,javascript,html,Javascript,Html,我在一个框架内有10个复选框,框架集为3 <frameset cols="16%,68%,16%"> <frame src="fish.html" name="bodyleft" noresize scrolling=no> <frame src="fish1.html" name="bodymid" noresize scrolling=no> <frame src="fish2.html" name="bodyright" n

我在一个框架内有10个复选框,框架集为3

<frameset cols="16%,68%,16%">
    <frame src="fish.html" name="bodyleft" noresize scrolling=no>
    <frame src="fish1.html" name="bodymid" noresize scrolling=no>
    <frame src="fish2.html" name="bodyright" noresize scrolling=no>
    </frameset>

fish1.html上的代码

<script type="text/javascript">
  function countCheckboxes ( ) 
  {
    var form = document.getElementById('testForm');
    var count = 0;
    for(var n=0;n < form.length;n++)
    {
      if(form[n].name == 'items[]' && form[n].checked)
      {
        count++;
      }
    }
    document.getElementById('checkCount').innerHTML = count;
  }
  window.onload = countCheckboxes;
</script>

函数计数复选框()
{
var form=document.getElementById('testForm');
var计数=0;
for(var n=0;n
是否可以计算fish2.html而不是fish1上的复选框数?我如何做到这一点?

尝试类似的方法(未测试):


@user2135437您的代码非常不清楚。您将获得id为的元素,然后在for中对其进行迭代(getElementById仅返回1个元素),而我猜这个元素不是表单,而是复选框
var frame2 = document.getElementById('bodyright');
window.onload = countCheckboxes(frame2);
function countCheckboxes (frame) 
{
   var forms = frame.document.getElementsByTagName('form');
   //...
}