以下為本站文章分類清單

  1. AJAXspacer
  2. ASPspacer
  3. CSSspacer
  4. Javascriptspacer
  5. Windows 應用程式spacer
  6. 網頁設計
  7. 評論、短文、雜文spacer
  8. 版主spacer
  9. 最新回應spacer

以下為本頁本文內容

Javascript 的條件陳述語法

Javascript 的條件陳述語法,列表如下:

語法 說明及範例
if

語法:

if (條件式){
   執行的動作....
}

當條件式為真時,執行大括號內的動作,如果要執行的動作,只有一項,大括號可以省略。

應用在條件式中的運算子(Operator)如下:

運算子 說明 運算子 說明
== 等於 != 不等於
> 大於 < 小於
>= 大於等於(不小於) <= 小於等於(不大於)
&& 且(and) || 或(or)
! 非(not)    

範例:

語法例 說明
if (a==1) 如果 a 的值等於1
if (a!='radio') 如果 a 的值不等於 radio(字串)
if (a>1 && b<0) 如果 a 大於 1 而且 b 小於 0
if (a=='' || a==null) 如果 a 是空字串或 null

 

if else

語法:

if (條件式){
   執行的動作A....
}else{
   執行的動作B...
}

同上,當條件式成立時,執行動作A,反之,執行動作B

switch

語法:

switch (檢查項){

case "狀況1" :

執行動作
break;

case "狀況2" :

執行動作
break;

case "狀況3" :

執行動作
break;

default :

執行動作
break;

}

switch 可看成是很複雜的 if...else 的組合,通常是在選擇項有超過兩種可能值時使用,例如處理日期,每周有七天,各有不同動作,這時選擇項就使用一個變數取得今天星期幾,再依周日到周六,作不同動作。

語法中,最後必需以 break 離開條件式。

範例:

var d=new Date().getDay();

switch(d){

case 0 : // 周日

執行動作
break;

case 6 : // 周六

執行動作
break;

default : // 其他周一到周五

執行動作
break;

}

 

?

問號是條件運算子,相當於 if...else... 的簡寫。

語法:

(條件式)?條件成立時:條件不成立時;

範例:

x=(ns)?e.pageX:event.x;
y=(ns)?e.pageY:event.y;

ns 本身就是一個真偽值,和下例相同

x=(navigator.appName == "Netscape")?e.pageX:event.x;
y=(navigator.appName == "Netscape")?e.pageY:event.y;

 

 

卜維丰 2/6 07'

以下為文章回應區

同意轉載,不過麻煩看一下轉載需知

What is the Ilizarov method?   2017/9/1 上午 01:34:00

I have read so many posts about the blogger lovers however this post is
truly a nice piece of writing, keep it up.

What causes pain in the back of the heel?   2017/8/29 上午 09:02:00

Have you ever considered creating an e-book
or guest authoring on other sites? I have a blog based upon on the same ideas you discuss and would really
like to have you share some stories/information. I know my visitors would value your work.
If you are even remotely interested, feel
free to send me an e mail.

check out your url   2017/8/28 下午 10:13:00

Incredible! This blog looks exactly like my old
one! It's on a entirely different subject but it has pretty much the same page layout and design. Great
choice of colors!

How do I stretch my Achilles tendon?   2017/8/27 下午 12:09:00

Aw, this was an extremely nice post. Taking the time and actual effort to produce a great article… but
what can I say… I put things off a lot and don't seem to get anything done.

How do you treat a sore Achilles tendon?   2017/8/21 下午 08:32:00

Way cool! Some very valid points! I appreciate you penning this post plus the rest of the website is very good.

What is a heel lift?   2017/8/4 下午 12:52:00

Hi, i believe that i noticed you visited my web site so i came to go
back the desire?.I'm trying to in finding things to improve my website!I suppose its ok to use
a few of your ideas!!

http://ivanahatchel.jimdo.com   2017/7/31 上午 02:04:00

I'm really loving the theme/design of your site. Do you ever run into any internet
browser compatibility problems? A few of my blog
readers have complained about my website not working correctly in Explorer but looks great in Chrome.
Do you have any suggestions to help fix this problem?

What causes pain in the Achilles tendon?   2017/7/28 下午 10:37:00

hello!,I really like your writing very a lot!
percentage we keep up a correspondence extra about your article on AOL?
I need an expert on this house to solve my problem. May
be that's you! Taking a look forward to look you.

Where are the femur tibia and fibula?   2017/7/22 下午 09:42:00

Hey There. I found your weblog the use of
msn. This is a very neatly written article. I'll make sure to bookmark
it and return to learn extra of your useful information. Thank you for the post.
I'll certainly comeback.

foot pain exercises   2017/7/2 下午 01:50:00

Outstanding story there. What happened after? Good luck!

سایت   2017/6/24 下午 07:36:00

My brother suggested I might like this website. He used to
be totally right. This publish truly made my day. You can not imagine just how a lot time I had spent for this
info! Thank you!

maricruzCuriel.jimdo.com   2017/5/8 下午 11:46:00

These are really great ideas in about blogging.

You have touched some pleasant factors here.

Any way keep up wrinting.

給個回應
姓名:
佈落格網址:
  如果您是要發問問題, 最好有個問題測試的網址, 這樣比較容易找到您問題所在, 謝謝
內容: