1 回答
TA贡献1875条经验 获得超3个赞
删除toFixed并设置div为浮动3.181818:
//obtain reference to number html element
var number = document.getElementById('number');
//obtain reference to output html element
var output = document.getElementById('output');
//what you want to divide to
var division = 3.181818; // can't be 0, or the world will explode
//add an eventlistener to the change event on the number element
number.addEventListener('keyup', function(e) {
//get the value from the input
var val = parseFloat(number.value);
//check if it is a nan
if (!isNaN(val)) {
output.innerHTML = val / division;
} else {
output.innerHTML = 'that\'s not a number!';
}
});
<input id="number" type="text"> ÷ 3.181818<br /> Your output is:
<div id="output"></div>
- 1 回答
- 0 关注
- 96 浏览
添加回答
举报