我在用戶輸入時正在進行一些實時計算。實時計算不起作用
這很奇怪,它在jsfiddle中工作,但不在localhost中。
window.onload = function() {
var base = 10;
var numberField = document.getElementById('numberField');
numberField.onkeyup = numberField.onpaste = function() {
if(this.value.length == 0) {
document.getElementById('result').innerHTML = '';
return;
}
var number = parseInt(this.value);
if(isNaN(number)) return;
document.getElementById('result').innerHTML = number * base;
};
numberField.onkeyup(); //could just as easily have been onpaste();
};
也許發佈工作jsfiddle。 – Bruno
這是小提琴http://jsfiddle.net/Dem6Q/176/ – user1851384