0
var one = document.getElementById('num');
var two = document.getElementById('nums');
var sumadd = document.getElementById('last');
one.addEventListener('input', myfun);
two.addEventListener('input', myfun);
function myfun() {
var one1 = parseFloat(one.value) || 0;
var two2 = parseFloat(two.value) || 0;
var sumval = one1 + two2;
sumadd.innerHTML = "The Sum of the two values are " +sumval;
}
<div id="footer">
<input type="text" id="num"/>
<input type="text" id="nums" />
<p id="last"></p>
</div>
請解決在鉻瀏覽器中出現此錯誤的問題。不知道問題出在哪裏Uncaught TypeError:無法在chrome瀏覽器中讀取屬性'addEventListener'爲null
PLease include html – Mairaj
看起來像「num」和「nums」不存在 –
var one = document.getElementById('num');'和其他類似的行在你的html完全加載之前執行。爲了解決這個問題,把它們放在'window.onload'方法中 –