javascript使用switch case实现动态改变超级链接文字及地址

前端技术 2023/09/04 JavaScript

代码很简单,我这里就不多废话了,小伙伴们直接看源码吧。

http://www.w3.org/TR/html4/loose.dtd\">
<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">
<title>动态改变超级链接文字及地址</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/(招商银行)\";
        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(兴业银行)\";
        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>请选择</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=\"#\" target=\"_blank\" id=\"shownetbank1\" name=\"shownetbank1\">未选择银行</a></div>
</body>
</html>

是不是超级简单实用呢。。。经常看看比较大的站,还是可以解除到不少好东西的。

本文地址:https://www.stayed.cn/item/11019

转载请注明出处。

本站部分内容来源于网络,如侵犯到您的权益,请 联系我

我的博客

人生若只如初见,何事秋风悲画扇。