1

我有基本的 JS 知识。

当来自的任何字段发生变化时,我需要触发下面的函数。在这里,它仅在 var2 更改时才有效,但我需要在任何 var# 更改时触发它。(我将在表格末尾有 30 个 var)

我想我需要一个 OR 条件,“if (var1.onchange OR var2.onchange OR ...) function()”

提前感谢您的宝贵意见!

<script>
window.onload = function () {
var var0 = document.getElementById('field09')
    var1 = document.getElementById('field10')
    var2 = document.getElementById('field11')
    storage = document.getElementById('field12')

var2.onchange= function()


  { 
storage.value = var0.value+" ; "+var1.value+" ; "+var2.value;
};
};
</script>
4

1 回答 1

2

请试试这个:

window.onload = function () {
    var var0 = document.getElementById('field09'),
        var1 = document.getElementById('field10'),
        var2 = document.getElementById('field11'),
        storage = document.getElementById('field12'),

        trigFunc = function(){ 
            storage.value = var0.value + " ; " + var1.value + " ; " + var2.value;
        }

    var0.onchange = trigFunc;
    var1.onchange = trigFunc;
    var2.onchange = trigFunc;
}

演示:jsfiddle

于 2013-07-15T07:30:54.617 回答