繁体   English   中英

为什么这在Chrome中有效,但在Firefox中不起作用?

[英]Why does this work in Chrome but not firefox?

function fill (colname) {
    var numRows, i, toCopy, iterated_name;

    numRows = document.getElementById('malesTable').rows.length + document.getElementById('femalesTable').rows.length - 2;
    //gets number of rows, subtracts two for header rows(male and female)
    toCopy = document.getElementById(colname.id).value;
    i = 1;
    //iterate over id's and input values
    for (i; i <= numRows; i++){
    iterated_name = colname.id + "_" + i;
    document.getElementById(iterated_name).value = toCopy;
    }
}

它将在chrome中工作,以自动填充许多字段,但是在Firefox中则不起作用。 为什么?

为了澄清何时将输入内容放入自动填充框,它不会按预期复制字段。

这是jsfiddle

http://jsfiddle.net/hopup/tfEQM

执行此操作时:

fill(external_id);

您在Firefox中传递的是未定义的,但在Chrome中传递的是元素,因为Chrome会使所有ID的元素污染全局范围。

想必您是说fill(document.getElementById("external_id"))吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM