html中如何点击下拉框在同一页打开特定页面的特定部位?
发布网友
发布时间:2022-04-21 09:59
我来回答
共1个回答
热心网友
时间:2022-04-21 11:29
第一个页面1.html:
<html>
<body>
<select id="procts" name="procts" onchange="window.location.href='1.html#'+this.value;window.onload();" >
<option value="All" selected="selected" >All</option>
<option value="1">Music</option>
<option value="2">Videos</option>
</select>
<div id="music">music</div>
<div id="videos">videos</div>
<script>
window.onload = function(){
var index = window.location.hash.substr(1);
if (index == 1) {
document.getElementById("music").style.display="block";
document.getElementById("videos").style.display="none";
document.getElementById("procts").value= "1";
}
else if(index == 2) {
document.getElementById("videos").style.display="block";
document.getElementById("music").style.display="none";
document.getElementById("procts").value= "2";
}
else{
document.getElementById("music").style.display="block";
document.getElementById("videos").style.display="block";
document.getElementById("procts").value= "ALL";
}
}
</script>
</body>
</html>
第二个页面2.html:
<html>
<body>
<select id="procts" name="procts" onchange="window.location.href='1.html#'+this.value" >
<option value="All" selected="selected" >All</option>
<option value="1">Music</option>
<option value="2">Videos</option>
</select>
</body>
</html>