javascript使用switch case实现动态改变超级链接文字及地址
代码很简单,我这里就不多废话了,小伙伴们直接看源码吧。
<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">
<title>动态改变超级链接文字及地址</title>
<linkhref="css/css.css"rel="stylesheet"type="text/css">
<scripttype="text/javascript"language="javascript">
functionnetbankusername()
{
values=form.bankname.options[form.bankname.selectedIndex].value;
texts=form.bankname.options[form.bankname.selectedIndex].text;
switch(form.bankname.selectedIndex)
{
case1:
//document.links[0].href="http://www.cmbchina.com/";
//shownetbank1.innerHTML="http://www.cmbchina.com/(招商银行)";
document.links[0].href=values;
shownetbank1.innerHTML=values+"("+texts+")";
break;
case2:
//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=values;
shownetbank1.innerHTML=values+"("+texts+")";
break;
default:
alert(form.bankname.selectedIndex);
break;
}
}
</script>
</head>
<body>
<formaction="cardinfo_action.asp?action=insert"method="post"name="form"id="form">
<tablewidth="200"border="0">
<tr>
<td>请选择</td>
<td>
<selectname="bankname"onChange="netbankusername()"id="bankname">
<optionvalue="">请选择</option>
<optionvalue="http://www.cmbchina.com/">招商银行</option>
<optionvalue="http://www.cib.com.cn/netbank/netbank.portal">兴业银行</option>
<optionvalue="http://www.baidu.com">其他</option>
</select></td>
</table>
</form>
<divstyle="border:1pxsolid#ccc;margin:1px;width:600px;height:20px;"><ahref="#"target="_blank"id="shownetbank1"name="shownetbank1">未选择银行</a></div>
</body>
</html>
是不是超级简单实用呢。。。经常看看比较大的站,还是可以解除到不少好东西的。