html怎么读取输入框的值并进行运算

 时间:2024-10-15 03:52:52

1、html:<h1>计算两个值之和</h1><input type="text" value=""/><span>+</span><input type="text" value=""/><span>=</span><span class="total"></span><button class="btn" onclick="total()">计算</button>

html怎么读取输入框的值并进行运算

2、css:h1{ text-align: center; line-height: 20px; font-si芰垄孕动ze: 16px;}input { width: 30%; height: 20px; line-height: 20px; border: 1px solid #2994CA;}span{ display: inline-block; width: 10%; text-align: center;}.total{ color: red;}.btn{ width: 20%; background: #2994CA; color: #fff; margin: 20px auto; display: block; height: 30px; border-radius: 5px;}

html怎么读取输入框的值并进行运算

3、js:function total(){ var number = 0; //获取所有的input,遍历获取值,进行相加 $("input").each(function(){ number += parseFloat($(this).val()); }); //将相加之和,显示到相应的位置 $(".total").html(number)}

html怎么读取输入框的值并进行运算
  • 怎样用setInterval和setTimeout实现显示时间?
  • php怎么连接数据库
  • python中设计类的三要素是什么
  • vscode在哪里设置鼠标光标动画
  • devc++如何导入visualc++项目
  • 热门搜索
    鹿晗为什么退出跑男 请假条怎么写 今天股市为什么大跌 油炸汤圆的做法 花呗怎么用 奶茶怎么做 早泄怎么办 猪皮冻怎么做 船怎么折 苹果怎么录屏