首页 > 代码库 > javascript switch case

javascript switch case

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>动态改变超级链接文字及地址</title>
<link href="http://www.mamicode.com/css/css.css" rel="stylesheet" type="text/css">
<script type="text/javascript" language="javascript">
function netbankusername()
{

values=form.bankname.options[form.bankname.selectedIndex].value;
texts=form.bankname.options[form.bankname.selectedIndex].text;

  switch (form.bankname.selectedIndex)
    {
       case 1:
        //document.links[0].href="http://www.cmbchina.com/";
        //shownetbank1.innerHTML="http://www.cmbchina.com/(招商银行)";
        document.links[0].href=http://www.mamicode.com/values;
        shownetbank1.innerHTML=values+"("+texts+")";
        break;
       case 2:
           //document.links[0].href="http://www.cib.com.cn/netbank/netbank.portal";
        //shownetbank1.innerHTML="http://www.cib.com.cn/netbank/netbank.portal(兴业银行)";
        document.links[0].href=http://www.mamicode.com/values;
        shownetbank1.innerHTML=values+"("+texts+")";
        break;
        default:
            alert(form.bankname.selectedIndex);
        break;
    }
}
</script>
</head>
<body>
<form action="cardinfo_action.asp?action=insert" method="post" name="form" id="form">
<table width="200" border="0"> 
<tr>   
<td>请选择</td>
<td>

<select name="bankname" onChange="netbankusername()" id="bankname">
<option value="">请选择</option>
<option value="http://www.cmbchina.com/">招商银行</option>
<option value="http://www.cib.com.cn/netbank/netbank.portal">兴业银行</option>
<option value="http://www.baidu.com">其他</option>
</select></td> 
</table>
</form>
<div style="border:1px solid #ccc;margin:1px;width:600px;height:20px;"><a href="http://www.mamicode.com/#" target="_blank" id="shownetbank1" name="shownetbank1">未选择银行</a></div>
</body>
</html>

javascript switch case