大大大大雄
2016-05-26 15:22
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Math </title>
<script type="text/javascript">
function dian(){
var i =document.getElementById("txt1").value;
var j =document.getElementById("txt2").value;
j =Math.ceil(i);
}
</script>
</head>
<body>
<form>
<input type="txt" name="文本" value="输入" id="txt1" /><br />
<input type="button" name="按钮" value="向上取整" onclick="dian()"/><br />
<input type="txt" name="文本" value="结果" id="txt2"/>
</form>
</body>
</html>
试试看
var i =parseInt(document.getElementById("txt1").value);
var j =Math.ceil(i);
document.getElementById("txt2").value=j;
input 的属性type="text"
i和j要用parseInt()强制转换
JavaScript进阶篇
468196 学习 · 21891 问题
相似问题