JavaScript | 嵌套if的示例

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 sa=parseInt(document.getElementById("txta").value);
var disc=0.0;
var np=0.0;
if(sa>0){
if(sa>5000){
if(sa>15000){
if(sa>30000){
disc=sa*0.4;
}
else{
disc=sa*0.25;
}
}
else{
disc=sa*0.15; 
}
}
else{
disc=sa*0.05;
}
document.getElementById("txtb").value=""+disc;
var np=sa-disc;
document.getElementById("txtc").value=""+np;
}
else{
alert('Invalid Sale Amount')
}
}
</SCRIPT>
</HEAD>
<BODY>
<h2>Nested If : True ladder</h2>
<hr />
<table>
<tr>
<td>
<label>Enter Sale Amount:</label>
</td>
<td>
<input type="text" name="txta" id="txta" />
</td>
</tr>
<tr>
<td>
&nbsp;
</td>
<td>
<input type="button" value="Calculate Discount" onclick="Calculate()" />
</td>
</tr>
<tr>
<td>
<label>Discount</label>
</td>
<td>
<input type="text" name="txtb" id="txtb" readonly />
</td>
</tr>
<tr>
<td>
<label>Net Pay</label>
</td>
<td>
<input type="text" name="txtc" id="txtc" readonly />
</td>
</tr>
</table>
</BODY>
</HTML>

Output

輸出量

JS | Example of Nested if

翻譯自: https://www.includehelp.com/code-snippets/nested-if-example-in-javascript.aspx

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/541276.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/541276.shtml
英文地址,請注明出處:http://en.pswp.cn/news/541276.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

POJ 1014 Dividing 背包

二進制優化&#xff0c;事實上是物體的分解問題。 就是比方一個物體有數量限制&#xff0c;比方是13&#xff0c;那么就須要把這個物體分解為1。 2&#xff0c; 4&#xff0c; 6 假設這個物體有數量為25&#xff0c;那么就分解為1&#xff0c; 2&#xff0c; 4。 8。 10 看出規…

node.js 中間件_Node.js中的Passport中間件(模塊)

node.js 中間件Hi! Welcome to Node.js Authentication Series, where well study and program the passport module or middleware. 嗨&#xff01; 歡迎使用Node.js身份驗證系列 &#xff0c;我們將在其中研究和編程通行證模塊或中間件 。 Nowadays, an important tool in m…

android開發自動提示框,Android 多種簡單的彈出框樣式設置代碼

簡介這是一個基于AlertDialog和Dialog這兩個類封裝的多種彈出框樣式&#xff0c;其中提供各種簡單樣式的彈出框使用說明。同時也可自定義彈出框。項目地址&#xff1a;http://www.easck.com/jjdxmashl/jjdxm_dialogui特性1.使用鏈式開發代碼簡潔明了2.所有的彈出框樣式都在Dial…

小程序中利用Moment.js格式時間

2019獨角獸企業重金招聘Python工程師標準>>> LeanCloud給的日期是ISO格式&#xff0c;比如2017-06-05T14:08:20.589Z&#xff0c;直接顯示在頁面上體驗不好。 凡是有關日期的&#xff0c;格式化、計算&#xff0c;用moment就夠了。 1.下載 http://momentjs.com/ 選m…

php 檢查數組為空_檢查數組是否為空在PHP中

php 檢查數組為空Given an array and we have to check if array is an empty or not using PHP. 給定一個數組&#xff0c;我們必須檢查數組是否為空或不使用PHP。 To check whether an array is empty or not, we can use a built-in function empty(), in other cases wher…

JEESZ分布式架構3--CentOs下安裝MySQL(環境準備)

聲明&#xff1a;因為運行環境是基于Linux系統的&#xff0c;在做此框架之前需要做一些前期的環境準備工作CentOs下安裝MySQL網上很多實例&#xff0c;因為博客后期作為框架的原生教程&#xff0c;故這邊做詳細的安裝記錄&#xff0c;我這邊已經下載好了MySQL&#xff0c;通過s…

一個函數里兩個setjmp_C語言中setjmp.h的longjmp()函數

一個函數里兩個setjmpWe can call this function as an advance version of goto statement but with more dynamic range. The longjump() function allows us to pass parameters to know that the control has been jumped or not. 我們可以將此函數稱為goto語句的高級版本&…

linux sublime nodejs,Ubuntu環境下sublime3 nodejs安裝與插件配置

1.sudo add-apt-repository ppa:webupd8team/sublime-text-3回車&#xff0c;出現很多信息。但是我們看看圖片最后字知道&#xff0c;這地方在等待我們確認是否添加這個倉庫&#xff0c;按enter鍵繼續&#xff0c;按crtlc取消。此時&#xff0c;按ENTER繼續&#xff0c;建立信任…

李洪強iOS開發之FMDB線程安全的用法

// // ViewController.m // 04 - FMDB線程安全的用法 // // Created by 李洪強 on 2017/6/6. // Copyright © 2017年 李洪強. All rights reserved. // #import "ViewController.h" //導入頭文件 #import "FMDB.h" interface ViewController () p…

SCHAR_MIN常數,C ++中的示例

C SCHAR_MIN宏常量 (C SCHAR_MIN macro constant) SCHAR_MIN constant is a macro constant which is defied in climits header, it is used to get the minimum value of a signed char object, it returns the minimum value that a signed char object can store, which i…

android分開兩個線程做事,android開發教程之handle實現多線程和異步處理

這次淺談一下Handler,為什么會出現Handler這個功能特性呢&#xff1f;首先&#xff0c;在之前的基本控件&#xff0c;基本都是在Activity的onCreate(Bundle savedInstanceState)方法中調用和處理的&#xff0c;但是&#xff0c;在有些情況&#xff0c;比如在網絡上下載軟件等一…

夏夜

兒時的夏夜畢竟是最有夏夜的味道。屋堂的煤油燈啪嗒的跳動&#xff0c;忽明忽暗&#xff0c;真怕它脆弱的明亮突然變黑暗。屋外彎月星稀&#xff0c;月光優雅的撒在平靜的湖面上&#xff0c;清純而又溫和。水鳥在湖岸邊慵懶的伸了伸脖子。正享受著夏夜的寧靜和清涼。調皮的小孩…

Python operator.lt()函數與示例

operator.lt()函數 (operator.lt() Function) operator.lt() function is a library function of operator module, it is used to perform "less than operation" on two values and returns True if the first value is less than the second value, False, otherw…

android實現滑動切換圖,Android:使用ViewPager實現左右滑動切換圖片加點點

圖片發自簡書App1、引入android-support-v4.jar包&#xff0c;在主布局里加入< ?xml version"1.0" encoding"utf-8"?>< RelativeLayout xmlns:android"http://schemas.android.com/apk/res/android"xmlns:tools"http://schemas.…

div的替代品

人們在標簽使用中最常見到的錯誤之一就是隨意將HTML5的<section>等價于<div>——具體地說&#xff0c;就是直接用作替代品(用于樣式)。在XHTML或者HTML4中&#xff0c;我們常看到這樣的代碼&#xff1a; <!-- HTML 4-style code --> <div id"wrapper…

threadgroup_Java ThreadGroup list()方法與示例

threadgroupThreadGroup類的list()方法 (ThreadGroup Class list() method) list() method is available in java.lang package. list()方法在java.lang包中可用。 list() method is used to list or display information (like name, priority, thread group, etc.) to the st…

html的柱狀圖去除右邊縱坐標,excel如何把次坐標軸逆序

excel2010設置水平坐標軸逆序類型,但垂直坐標軸刻設置水平坐標軸逆序且垂直坐標軸軸仍位于圖表左側的步驟是&#xff1a;打開帶有圖表的Excel工作表&#xff1b;在圖表區域的水平軸標簽位置雙擊鼠標左鍵&#xff0c;打開“設置坐標軸格式”&#xff1b;勾尋逆序類別”&#xff…

jhipster項目遷移websocket

2019獨角獸企業重金招聘Python工程師標準>>> 1、 在項目目錄下命令行安裝 兩個組件 bower install sockjs-client bower install stomp-websocket 2、在index.html 中加入組件js的引用 <script src"bower_components/sockjs-client/dist/sockjs.js">…

Java包hashCode()方法及示例

包類hashCode()方法 (Package Class hashCode() method) hashCode() method is available in java.lang package. hashCode()方法在java.lang包中可用。 hashCode() method is used to return the hashcode of the package calculated from the package name. hashCode()方法用…

html 圖片上放置按鈕,用CSS在圖片上再加一個小按鈕

很簡單的&#xff0c;嗯&#xff0c;就是要做成這樣的&#xff1a;用CSS&#xff0c;當然得用層了&#xff0c;就是在圖片上再加一個層&#xff0c;用來放那個按鈕&#xff0c;按鈕又有兩種方式可以放&#xff0c;一種是直接用圖片img標簽&#xff0c;一種是通過背景圖片放上去…