发布网友 发布时间:2022-04-23 15:51
共4个回答
热心网友 时间:2023-10-08 22:27
这个代码应该可以帮你
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="js/jquery-1.8.2.min.js"></script>
</head>
<body>
<table>
<tr>
<td>水果</td>
<td>原价(元)</td>
<td>折扣</td>
<td>价格(元)</td>
</tr>
<tr>
<td class="fruit"></td>
<td class="jia"></td>
<td class="zhe"></td>
<td class="price"></td>
</tr>
</table>
<script>
var a1 = ["苹果", "香蕉", "橘子", "梨"];
var a2 = [10, 12, 15, 9];
var a3 =[0.9,0.8,0.7];
var index1 = Math.floor(Math.random() * a1.length);
var index2 = Math.floor(Math.random() * a3.length);
$(".fruit").html(a1[index1]);
$(".jia").html(a2[index1]);
$(".zhe").html(a3[index2]);
$(".price").html((a2[index1]*a3[index2]).toFixed(2));
</script>
</body>
</html>
追问那个,我还没有学到jquery,能否不用jQuery。追答
无标题文档
ul,li{padding: 0px; margin: 0px; list-style: none;}
.main{ width: 300px; height: 50px; margin: 0px auto;}
.main li{ width:98px; height: 50px; float: left; border: 1px solid #cecece}
var a1=["苹果","香蕉","橘子","梨"];
var a2=["10","12","15","9"];
var a3=["0.9","0.8","0.7"]
var a4 = new Array();
a4["0.9"] = "九折";
a4["0.8"] = "八折";
a4["0.7"] = "七折";
var index = Math.floor((Math.random()*a1.length));
var cccc = Math.floor((Math.random()*a4.length));
window.onload=function()
{
document.getElementById('sg').innerHTML=a1[index];
document.getElementById('yj').innerHTML=a2[index];
document.getElementById('zk').innerHTML=a4[a3[cccc]];
document.getElementById('jg').innerHTML=a2[index]*a3[cccc]+"元";
}
水果和原价
折扣
价格
,元
热心网友 时间:2023-10-08 22:27
在输入框里 写上 水果名 确认 得到 结果!
热心网友 时间:2023-10-08 22:28
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style>
ul,li{padding: 0px; margin: 0px; list-style: none;}
.main{ width: 300px; height: 50px; margin: 0px auto;}
.main li{ width:98px; height: 50px; float: left; border: 1px solid #cecece}
</style>
</head>
<body>
<script>
var a1=["苹果","香蕉","橘子","梨"];
var a2=["10","12","15","9"];
var a3=["0.9","0.8","0.7"]
var a4 = new Array();
a4["0.9"] = "九折";
a4["0.8"] = "八折";
a4["0.7"] = "七折";
var index = Math.floor((Math.random()*a1.length));
var cccc = Math.floor((Math.random()*3));
window.onload=function()
{
document.getElementById('sg').innerHTML=a1[index];
document.getElementById('yj').innerHTML=a2[index];
document.getElementById('zk').innerHTML=a4[a3[cccc]];
document.getElementById('jg').innerHTML=a2[index]*a3[cccc]+"元";
}
</script>
<div class="main">
<li>水果和原价</li>
<li>折扣</li>
<li>价格</li>
<li><span id="sg"></span>,<span id="yj"></span>元</li>
<li id="zk"></li>
<li id="jg"></li>
</div>
</body>
</html>
热心网友 时间:2023-10-08 22:28
下标和下标对应追问然后捏