html中如何点击下拉框在同一页打开特定页面的特定部位?

有两个页面,每个页面都有同样的下拉框html:<selectid="products"name="products"onchange="show(this.value)"... 有两个页面,每个页面都有同样的下拉框
html:
<select id="products" name="products" onchange="show(this.value)" >
<option value="All" selected="selected" >All</option>
<option value="1">Music</option>
<option value="2">Videos</option>
</select>
只有第一个页面有#music和#videos的div。
JS:
function show(index) {
if (index == 1) {
document.getElementById("music").style.display="block";
document.getElementById("videos").style.display="none";
}
else if(index == 2) {
document.getElementById("videos").style.display="block";
document.getElementById("music").style.display="none";
}
else{
document.getElementById("music").style.display="block";
document.getElementById("videos").style.display="block";
}
}
如何在第二个页面点击 music跳转到第一个页面只显示music的部分呢?
展开
 我来答
Homfen
2013-11-27 · TA获得超过163个赞
知道答主
回答量:57
采纳率:0%
帮助的人:51.1万
展开全部

第一个页面1.html:

<html>
<body>
<select id="products" name="products" 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("products").value= "1";
    }
    else if(index == 2) {
        document.getElementById("videos").style.display="block";
        document.getElementById("music").style.display="none";  
        document.getElementById("products").value= "2";        
    }
    else{
        document.getElementById("music").style.display="block";
        document.getElementById("videos").style.display="block"; 
        document.getElementById("products").value= "ALL";
    }
}
</script>
</body>
</html>


第二个页面2.html:

<html>
<body>
    <select id="products" name="products" 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>
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式