在Web開發過程中領導或者客戶經常想要增加全局搜索框功能。
搜素框使用select標籤搭配option標籤實現搜索框以及下拉列表功能。option標籤實現超鏈接跳轉功能也成爲需求之一。以下提供option標籤實現超鏈接跳轉功能主要代碼。模糊查詢+option超鏈接跳轉功能代碼在GitHub主頁(https://github.com/Shaoyc)更新。
html代碼:
<select onchange="GotoURL(this)">
<option value="">選項一</option>
<option value="">選項二</option>
<option value="">選項三</option>
</select>
<script>
function GotoURL(this) {
var doctext=this.options[this.selectedIndex].text;
if (doctext == "選項一") {
open("http://www.baidu.com",'_blank');
sobj.selectedIndex=0;
sobj.blur();
}
}
</script>