JavaScriptÖÐifÓëcase±È½Ï
·¢ÏÖ×Ô¼º´úÂëÖÐÓÃifµÄµØ·½±È½Ï¶à£¬ÓÚÊǾÍÔÚÉÏÖܶÔcaseÓï¾äºÃºÃÑо¿ÁËÒ»·¬²¢ÓÅ»¯ÁË×Ô¼ºµÄ²¿·Ö´úÂë¡£Òò´Ë³öÏÖÁËÈçÏÂifºÍcaseµÄ±È½Ïһ˵¡£ÉùÃ÷µ±caseµÄÌõ¼þ¿éÖÐûÓÃbreakʱºò£¬ÊǺÍifÒ»ÑùµÄÒ»¸öÒ»¸öµÄÌõ¼þÀ´ÅжÏÖ´ÐС£µ±Ìõ¼þÖÐÓÐÁËbreak£¬±àÒëÆ÷»áΪËü×ö¶þ·Ö·¨ÓÅ»¯(»òÌøת±í)£¬¾ÍÊǸù¾ÝÌõ¼þÀ´Ìøת£¬Æ½¾ùÐÔÄܸßÓÚif¡£
¶¨Ò壺 docStatus¸ÃÎĵµµÄµ±Ç°×´Ì¬
if Óï¾ä
ÔÚÒ»¸öÖ¸¶¨µÄÌõ¼þ³ÉÁ¢Ê±Ö´ÐдúÂë¡£
Óï·¨£ºif(Ìõ¼þ)
{
Ìõ¼þ³ÉÁ¢Ê±Ö´ÐдúÂë
}
Àý×Ó£ºif(docStatus=="ͨ¹ý")
{
alert(“ÎĵµµÄµ±Ç°×´Ì¬ÎªÍ¨¹ý”);
}
˵Ã÷£º docStatus¸ÃÎĵµµÄµ±Ç°×´Ì¬
×¢Ò⣺ʹÓÃË«µÈºÅ (==) À´±È½Ï±äÁ¿£¡ÔÚÓï·¨ÖÐûÓÐ else¡£½ö½öµ±Ìõ¼þΪ true ʱ£¬´úÂë²Å»áÖ´ÐС£
if...else Óï¾ä
ÔÚÖ¸¶¨µÄÌõ¼þ³ÉÁ¢Ê±Ö´ÐдúÂ룬µ±Ìõ¼þ²»³ÉÁ¢Ê±Ö´ÐÐÁíÍâµÄ´úÂë¡£ Èç¹ûÏ£ÍûÌõ¼þ³ÉÁ¢Ê±Ö´ÐÐÒ»¶Î´úÂ룬¶øÌõ¼þ²»³ÉÁ¢Ê±Ö´ÐÐÁíÒ»¶Î´úÂ룬ÄÇô¿ÉÒÔʹÓà if....else Óï¾ä¡£
Óï·¨£ºif(Ìõ¼þ)
{
Ìõ¼þ³ÉÁ¢Ê±Ö´ÐдúÂë
}
else
{
Ìõ¼þ²»³ÉÁ¢Ê±Ö´ÐдúÂë
}
Àý×Ó£ºif(docStatus=="ͨ¹ý")
{
alert(“ÎĵµµÄµ±Ç°×´Ì¬ÎªÍ¨¹ý”);
}
else
{
alert(“ÎĵµµÄµ±Ç°×´Ì¬ÎªÃ»ÓÐͨ¹ý”);
}
if...else if....else Óï¾ä
ʹÓÃÕâ¸öÓï¾ä¿ÉÒÔÑ¡ÔñÖ´ÐÐÈô¸É¿é´úÂëÖеÄÒ»¸ö¡£
µ±ÐèҪѡÔñ¶àÌ×´úÂëÖеÄÒ»Ì×À´ÔËÐÐʱ£¬ÇëʹÓà if....else if...else Óï¾ä¡£
Óï·¨£ºif(Ìõ¼þ1)
{
Ìõ¼þ1³ÉÁ¢Ê±Ö´ÐдúÂë
}
else if (Ìõ¼þ2)
{
Ìõ¼þ2³ÉÁ¢Ê±Ö´ÐдúÂë
}
else
{
Ìõ¼þ1ºÍÌõ¼þ2¾ù²»³ÉÁ¢Ê±Ö´ÐдúÂë
}
Àý×Ó£ºif(docStatus=="ÐÂÎĵµ")
{
&nb
Ïà¹ØÎĵµ£º
˽ÓбäÁ¿ ÔÚ¶ÔÏóÄÚ²¿Ê¹ÓÃ'var'¹Ø¼ü×ÖÀ´ÉùÃ÷£¬¶øÇÒËüÖ»Äܱ»Ë½Óк¯ÊýºÍÌØȨ·½·¨·ÃÎÊ¡£
˽Óк¯Êý ÔÚ¶ÔÏóµÄ¹¹Ô캯ÊýÀïÉùÃ÷£¨»òÕßÊÇͨ¹ývar functionName=function(){...}À´¶¨Ò壩£¬ËüÄܱ»ÌØȨº¯Êýµ÷Ó㨰üÀ¨¶ÔÏóµÄ¹¹Ô캯Êý£©ºÍ˽Óк¯Êýµ÷Óá£
ÌØȨ·½·¨ ͨ¹ýthis.methodName=function(){...}À´ÉùÃ÷¶øÇÒ¿ÉÄܱ»¶ÔÏóÍⲿµÄ´úÂëµ ......
<script type="text/javascript">
function fnOnPageChanged(page) {
var url = '<?=url('ShowFront','Search',$Request);?>' + '&page=' + page;
//alert(url);
document.location.href = url;
}
</script>
<select id="selectPage" onChange="fnOnPageC ......
JavaScriptÖеıհüÓеãÀàËÆÓÚjavaÖеľ²Ì¬·½·¨£¬¶ÔÓÚ°üÖеķ½·¨²»ÒªÈ¥ÊµÀý»¯¿ÉÒÔÖ±½ÓʹÓã¬ËüµÄ×÷·¨ÈçÏÂËùÒÔ¡£
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
< ......
JavaScriptÔËÐдúÂë¿ò´úÂë
<script language="JavaScript" type="text/JavaScript">
//ÔËÐÐÎı¾Óò´úÂë
function runEx(cod1) {
cod=document.all(cod1)
var code=cod.value;
if (code!=""){
var newwin=window.open(’’,’’,’’); //´ò¿ªÒ»¸ö´°¿Ú²¢¸³¸ø±äÁ¿newwin¡£ ......