<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>自动输出折扣价格js代码</title>
<script type="text/javascript">
window.onload=yunfei_s; //自动执行
function yunfei_s() {
var shijifeiyong = 80; //打折多少
var percen=document.getElementById('price1').innerHTML; //得到原有价格
var zongfeiyong; //定义一个存储变量
zongfeiyong = shijifeiyong*(percen/100); //计算
document.getElementById ('price2').innerHTML = parseFloat(zongfeiyong).toFixed(2); //输出到price2
}
</script>
</head>
<body >
<div id="price1" >100</div>
<div id="price2">1</div>
</body>
</html>
最后修改:2021 年 04 月 02 日 07 : 29 PM
© 允许规范转载