Welcome to Delicate template
Header
Just another WordPress site
Header

使用下拉框链接到另外的网站

7月 7th, 2011 | Posted by 无 名 in html | js

方法一:
onChange=”window.open(this.options[this.selectedIndex].value,”,”)”
这里调用了javascript事件:onChange//当改变时

函数:windows.open(url,…)
其中url的值是this.options[this.selectedIndex].value;

例子1:

<form>
<select size="1" font-size: 9pt" name="D1" onChange="window.open(this.options[this.selectedIndex].value,'','')">
<option value="#" selected>请选择站点</option>
<option value=http://www.zjnw.gov.cn>浙江农经网</OPTION>
<option value=http://www.sxnw.net>陕西兴农网</OPTION>
<option value=http://www.sdxnw.gov.cn>山东兴农网</OPTION>
</select>
</form>

例子2:
在以前的网页上变,不用弹出一个新窗口

<form>
<select size="1" font-size: 9pt" name="D1" onChange="window.open(this.options[this.selectedIndex].value,'_self')">
<option value="#" selected>请选择站点</option>
<option value=http://www.zjnw.gov.cn>浙江农经网</OPTION>
<option value=http://www.sxnw.net>陕西兴农网</OPTION>
<option value=http://www.sdxnw.gov.cn>山东兴农网</OPTION>
</select>
</form>

方法二:
写入函数。

<select onchange="Open(this);" name="select2">
<option value="#" selected>请选择站点</option>
<option value=http://www.zjnw.gov.cn>浙江农经网</OPTION>
<option value=http://www.sxnw.net>陕西兴农网</OPTION>
<option value=http://www.sdxnw.gov.cn>山东兴农网</OPTION>
</select>
<script language="javascript">
function Open(thisform){
if (thisform.options[thisform.selectedIndex].value.length>0)
window.open(thisform.options[thisform.selectedIndex].value);
}
</script>

You can follow any responses to this entry through the RSS 2.0 Both comments and pings are currently closed.