简体   繁体   English

如何将var值传递给javascript中的参数?

[英]How to pass var values to a parameter in javascript?

I was trying to use 2 different tables, different input field, and different text in a single script. 我试图在一个脚本中使用2个不同的表,不同的输入字段和不同的文本。 I use this script below to pass those values on a function parameter to get those values. 我在下面使用此脚本在功能参数上传递这些值以获得这些值。 The problem is I am not getting the input.value but I can get the input1.value . 问题是我没有得到input.value但我可以得到input1.value I think the input1 is not going inside the filterFunction(input) above 我认为input1不在上面的filterFunction(input)内部

<script type="text/javascript">
    function filterFunction(table, input, total_amount_id) {
        var filter, tr, td, i, totalViewable = 0;
        console.log(input1.value);
        console.log(input);
        filter = input.value.toUpperCase();
        tr = table.getElementsByTagName("tr");
            for (i = 0; i < tr.length; i++) {
            td = tr[i].getElementsByTagName("td")[1];
            tds = tr[i].getElementsByTagName("td")[0];
            if (td) {
                if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
                    tr[i].style.display = "";
                    totalViewable += parseFloat(tds.innerHTML);
                    document.getElementById(total_amount_id).innerHTML = "$" + totalViewable.toFixed(2);
                } else {
                    tr[i].style.display = "none";
                }
            }
        }
    }
    var table1 = document.getElementById("dateTable");
    var input1 = document.getElementById("event_date_range");
    var total_amount_id1 = "total_amount_td";
    filterFunction(table1, input1, total_amount_id1);
    var table2 = document.getElementById("dateTable2");
    var input2 = document.getElementById("event_date_range2");
    var total_amount_id2 = "total_amount_td2";
    filterFunction(table2, input2, total_amount_id2);
</script>
var input1 = document.getElementById("event_date_range"); 

In this expression you are placing value in input1 . 在此表达式中,您将值放置在input1 so you cannot ge the {input} value. 因此您无法使用{input}值。

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

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