网站需要哪些,郑州做网站推广哪家好,加强网站备案管理,私人订制网站建设Example: 例#xff1a; In this example, we are reading salary of an employee and finding the discount and net pay based on given salary and discount rate. 在此示例中#xff0c;我们正在读取员工的薪水#xff0c;并根据给定的薪水和折扣率找到折扣和净工资。 …Example: 例 In this example, we are reading salary of an employee and finding the discount and net pay based on given salary and discount rate. 在此示例中我们正在读取员工的薪水并根据给定的薪水和折扣率找到折扣和净工资。 Code (JS HTML): 代码(JS和HTML) !DOCTYPE html
HTML
HEAD
SCRIPT
function Calculate(){
var saparseInt(document.getElementById(txta).value);
var disc0.0;
var np0.0;
if(sa0){
if(sa5000){
if(sa15000){
if(sa30000){
discsa*0.4;
}
else{
discsa*0.25;
}
}
else{
discsa*0.15;
}
}
else{
discsa*0.05;
}
document.getElementById(txtb).valuedisc;
var npsa-disc;
document.getElementById(txtc).valuenp;
}
else{
alert(Invalid Sale Amount)
}
}
/SCRIPT
/HEAD
BODY
h2Nested If : True ladder/h2
hr /
table
tr
td
labelEnter Sale Amount:/label
/td
td
input typetext nametxta idtxta /
/td
/tr
tr
td
nbsp;
/td
td
input typebutton valueCalculate Discount onclickCalculate() /
/td
/tr
tr
td
labelDiscount/label
/td
td
input typetext nametxtb idtxtb readonly /
/td
/tr
tr
td
labelNet Pay/label
/td
td
input typetext nametxtc idtxtc readonly /
/td
/tr
/table
/BODY
/HTML
Output 输出量 翻译自: https://www.includehelp.com/code-snippets/nested-if-example-in-javascript.aspx