问题:折扣价格计算创建一个网页来计算特定季节的产品折扣。有折扣率的季节是夏季(10%)、新年(5%)和清关(15%)。折扣是根据产品的价格计算的。网页应该看起来像

结果网页应该看起来像

代码:
function calculate() {
var se = document.getElementById("season").value;
var pr = document.getElementById("price").value;
var dist;
if (se == "summer") {
document.getElementById("discount").innerHTML = "The discount is 10%";
dist = (pr - (pr * 0.1));
document.getElementById("result").innerHTML = "The discounted price : Rs " + dist;
return false;
} else if (se == "newyear") {
document.getElementById("discount") innerHTML = "The discount is 5% ";
dist = (pr - (pr * 0.05));
document.getElementById("result").innerHTML = "The discounted price : Rs " + dist;
return false;
} else if (se == "clearance") {
document.getElementById("discount").innerHTML = "The discount is 15%";
dist = (pr - (pr * 0.15));
document.getElementById("result").innerHTML = "The discounted price : Rs " + dist;
return false;
}
return false;
}body {
background-color: #99FFFF;
}
h1 {
font-style: italic;
font-weight: bold;
text-align: center;
color: #b03060;
}
table {
float: left;
width: 35%;
border: 5px solid;
border-width: 30%;
padding: 10px;
}
#submit {
float: left;
width: 45%;
}
tr,
td {
padding: 10px;
border-style: solid;
border-width: 2px;
}
#result {
font-style: italic;
color: #FF0000;
font-size: 40px;
text-align: center;
font-weight: bold;
}
#discount {
font-size: 25px;
font-weight: bold;
text-align: center;
}<!-- This is a partial code. Implement the essential codes required -->
<!-- Do not modify the name or id of the components given in the code skeleton -->
<h1>DISCOUNT PRICE</h1>
<form onsubmit="return calculate()">
<table>
<tr>
<td>Product Name</td>
<td><input type="text" name="name" id="name" pattern="^[A-Za-z- ]+$" required></td>
</tr>
<tr>
<td>Product Price</td>
<td><input type="number" name="price" id="price" min="15001" required></td>
</tr>
<tr>
<td>Season</td>
<td>
<select name="season" id="season">
<option value="summer">SUMMER SALE</option>
<option value="newyear">NEW YEAR SALE</option>
<option value="clearance">CLEARANCE SALE</option>
</select>
</td>
</tr>
</table>
<br>
<input type="submit" name="submit" id="submit" value="GET DISCOUNT PRICE">
<div id="discount"></div>
<div id="result"></div>
</form>
计算时错误:
失败1:
com.gargoylesoftware.htmlunit.ScriptException:
缺失;构建信息:版本:'2.52.0',修订版:‘4c2593cfc3689a7fcd7be2549167e5ccc93ad28’,时间:'2016-02-11 :22:43‘系统信息:主机:’IP172-31-11-55‘,ip:'172.31.11.55',os.name:'Linux',os.arch:’amd64 64‘,os.version:’4.4.1-1128‘,java.version:‘1.8.0_292’驱动程序信息: driver.version: HtmlUnitDriver
失败2:
com.gargoylesoftware.htmlunit.ScriptException:
缺失;构建信息:版本:'2.52.0',修订版:‘4c2593cfc3689a7fcd7be2549167e5ccc93ad28’,时间:'2016-02-11 :22:43‘系统信息:主机:’IP172-31-11-55‘,ip:'172.31.11.55',os.name:'Linux',os.arch:’amd64 64‘,os.version:’4.4.1-1128‘,java.version:‘1.8.0_292’驱动程序信息: driver.version: HtmlUnitDriver
失败3:
com.gargoylesoftware.htmlunit.ScriptException:
缺失;构建信息:版本:'2.52.0',修订版:‘4c2593cfc3689a7fcd7be2549167e5ccc93ad28’,时间:'2016-02-11 :22:43‘系统信息:主机:’IP172-31-11-55‘,ip:'172.31.11.55',os.name:'Linux',os.arch:’amd64 64‘,os.version:’4.4.1-1128‘,java.version:‘1.8.0_292’驱动程序信息: driver.version: HtmlUnitDriver
发布于 2021-05-20 20:14:05
你错过了一段时间
document.getElementById("discount")innerHTML="The discount is 5% ";
<!-- This is a partial code. Implement the essential codes required -->
<!-- Do not modify the name or id of the components given in the code skeleton -->
<!DOCTYPE html>
<html>
<head>
<style>
body
{
background-color:#99FFFF;
}
h1
{
font-style:italic;
font-weight:bold;
text-align:center;
color:#b03060;
}
table
{
float:left;
width:35%;
border:5px solid;
border-width:30%;
padding:10px;
}
#submit
{
float:left;
width:45%;
}
tr,td
{
padding: 10px;
border-style:solid;
border-width:2px;
}
#result
{
font-style: italic;
color:#FF0000;
font-size:40px;
text-align:center;
font-weight:bold;
}
#discount
{
font-size:25px;
font-weight:bold;
text-align:center;
}
</style>
</head>
<body>
<h1>DISCOUNT PRICE</h1>
<form onsubmit="return calculate()">
<table>
<tr>
<td>Product Name</td>
<td><input type="text" name="name" id="name" pattern="^[A-Za-z- ]+$" required></td>
</tr>
<tr>
<td>Product Price</td>
<td><input type="number" name="price" id="price" min="15001" required></td>
</tr>
<tr>
<td>Season</td>
<td>
<select name="season" id="season">
<option value="summer">SUMMER SALE</option>
<option value="newyear">NEW YEAR SALE</option>
<option value="clearance">CLEARANCE SALE</option>
</select>
</td>
</tr>
</table>
<br>
<input type="submit" name="submit" id="submit" value="GET DISCOUNT PRICE">
<div id="discount"></div>
<div id="result"></div>
</form>
<script>
function calculate()
{
var se=document.getElementById("season").value;
var pr=document.getElementById("price").value;
var dist;
if(se=="summer")
{
document.getElementById("discount").innerHTML="The discount is 10%";
dist=(pr-(pr*0.1));
document.getElementById("result").innerHTML="The discounted price : Rs "+dist;
return false;
}
else if(se=="newyear")
{
document.getElementById("discount").innerHTML="The discount is 5% ";
dist=(pr-(pr*0.05));
document.getElementById("result").innerHTML="The discounted price : Rs "+dist;
return false;
}
else if(se=="clearance")
{
document.getElementById("discount").innerHTML="The discount is 15%";
dist=(pr-(pr*0.15));
document.getElementById("result").innerHTML="The discounted price : Rs "+dist;
return false;
}
return false;
}
</script>
</body>
</html>
https://stackoverflow.com/questions/67627096
复制相似问题