我想在第二个链接处于事件状态时共享页面(例如“http://mypage#green-color”)。
我尝试添加到第二个链接 onClick="window.location='#green-color';"
属性。它更改了浏览器地址窗口中的 URL,但我无法与其他人共享。
<a href="#" id="all">All Colors</a>
<a href="#green" id="green-color">Green Color</a>
<div id="red"></div>
<div id="green"></div>
页面的两种状态:
$( "#all" ).click(function() {
$( "#red" ).show(200);
});
$( "#green-color" ).click(function() {
$( "#red" ).hide(200);
});
最佳答案
尝试在 URL 中传递 divId
像这样
onClick="window.location='#green';"
对于效果,请使用 window.location.hash
方法。
var hashValue=window.location.hash;
if(hashValue=="#green")
{
$( "#red" ).hide(200);
}
关于javascript - 如何使URL链接到页面的另一种状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19766668/