问答详情
源自:7-13 向上取整ceil()

这样怎么不行?

<!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>


提问者:大大大大雄 2016-05-26 15:22

个回答

  • UltramanNexus
    2016-05-26 16:01:38
    已采纳

    试试看

    var i =parseInt(document.getElementById("txt1").value);

    var  j =Math.ceil(i);

    document.getElementById("txt2").value=j;


  • ZQ_Gumgum
    2016-07-28 16:13:13

    input 的属性type="text"

  • 安静滴杰先森3167148
    2016-05-26 16:47:40

    i和j要用parseInt()强制转换