Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.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 从iframe中的表计算总和_Javascript_Jquery_Html - Fatal编程技术网

Javascript 从iframe中的表计算总和

Javascript 从iframe中的表计算总和,javascript,jquery,html,Javascript,Jquery,Html,我有一个主页和一个子页(框架)。框架包含一个表,该表在列中包含数字。我想把这些数字加起来,从主页上得到结果 现在我的问题是我不知道如何访问frame表中的s <iframe id="iframe_form" name="iframe_form" src="ServicesList_guest_form.php" frameborder=0 style="width:540px;height:900px;position:absolute;top:710px;" ></ifram

我有一个主页和一个子页(框架)。框架包含一个表,该表在列中包含数字。我想把这些数字加起来,从主页上得到结果

现在我的问题是我不知道如何访问frame表中的
s

<iframe id="iframe_form" name="iframe_form" src="ServicesList_guest_form.php"
frameborder=0 style="width:540px;height:900px;position:absolute;top:710px;" ></iframe>

感谢您的帮助

您可以通过以下(IE8或更高版本)访问iframe的文档,请参阅

  • $(“#iframe_form”)获取jQuery包装器
  • [0]获取基础DOM引用
  • .contentWindow.document是文档
像这样

var innerDoc = $("#iframe_form")[0].contentWindow.document;
然后可以使用jQuery查找元素

console.log($(innerDoc).find("#mytable input"));
然后可以通过循环进行求和

var total = 0;
$(innerDoc).find("#mytable input").each(function(index) {
    var value = parseInt($(this).val(), 10);
    if (! isNaN(value)) { // just in case field is empty or user garbage
        total += value;
    }
});
console.log(total);

显示一些代码,您尝试了什么吗?如果我用class='sum'对每个输入进行求和,那么
查找
查询应该是什么?查询应该是“input.sum”
var total = 0;
$(innerDoc).find("#mytable input").each(function(index) {
    var value = parseInt($(this).val(), 10);
    if (! isNaN(value)) { // just in case field is empty or user garbage
        total += value;
    }
});
console.log(total);