这个代码应该可以帮你
水果 | 原价(元) | 折扣 | 价格(元) |
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));
在输入框里 写上 水果名 确认 得到 结果!
无标题文档
水果和原价
折扣
价格
,元
下标和下标对应