동경 2020-02-28 03:10 采纳率: 0%
浏览 287

js 增号按钮和减号按钮行不通

<html>
<head>
<script>
    var count = 1;
    var countEl = document.getElementById("count");
    function plus(){
        count++;
        countEl.value = count;
    }
    function minus(){
        if (count > 1) {
            count--;
            countEl.value = count;
        }
    }
</script>
</head>
<body>
<div >
    <button type="button">
    <i onclick="minus()"></i></button>
    <input type="text" id="count" value="1" >
    <button type="button">
    <i onclick="plus()"></i></button>
</div>
</body>

</html>

问题是按加号按钮和减号按钮都没有反应。
还有js里提示不能用value 我不知道该怎么办?

  • 写回答

4条回答 默认 最新

  • 叫兽-郭老师 新星创作者: Java技术领域 2020-02-28 09:26
    关注
    <button type="button" onclick="minus()"></button>
        <input type="text" id="count" value="1" >
        <button type="button" onclick="plus()">
        </button>
    

    js
    document.getElementById("count").html(count);

    评论

报告相同问题?