我有一个基本的JS知识。
当from中的任何字段发生变化时,我需要触发下面的函数。这里它仅在var2发生变化时有效但我需要在任何var#发生变化时触发它。 (我将在表格末尾有30个变量)
我想我需要一个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>
答案 0 :(得分:1)
请试试这个:
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