javascript USES switch case to dynamically change hyperlink text and address

  • 2020-05-05 10:57:28
  • OfStack

The code is very simple, I here is not much nonsense, friends directly look at the source bar.


<!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> Dynamically change hyperlink text and address </title>
<link href="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/( China merchants bank, )";
        document.links[0].href=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( Societe generale )";
        document.links[0].href=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> Please select a </td>
<td>
<select name="bankname" onChange="netbankusername()" id="bankname">
<option value=""> Please select a </option>
<option value="http://www.cmbchina.com/"> China merchants bank, </option>
<option value="http://www.cib.com.cn/netbank/netbank.portal"> Societe generale </option>
<option value="http://www.baidu.com"> other </option>
</select></td> 
</table>
</form>
<div style="border:1px solid #ccc;margin:1px;width:600px;height:20px;"><a href="#" target="_blank" id="shownetbank1" name="shownetbank1"> Unselected bank </a></div>
</body>
</html>

Isn't it super simple and practical... Often look at the larger station, or can be lifted to a lot of good things.


Related articles: