我有兩頁。一個是顯示隱藏div從另一頁onclick
<html>
<head>
<script language="javascript">
function toggleDiv(divid){
if(document.getElementById(divid).style.display == 'none'){
document.getElementById(divid).style.display = 'block';
}else{
document.getElementById(divid).style.display = 'none';
}
}
</script>
</head>
<body>
<a name="div1" href="javascript:;" onmousedown="toggleDiv('div1');"><p><b>Section 1</b> </p></a>
<div id="div1" style="display:none">
Content for section 1.
</div>
<a name="div2" href="javascript:;" onmousedown="toggleDiv('div2');"><p><b>Section 2</b></p></a>
<div id="div2" style="display:none">
Content for section 2.
</div>
</body>
</html>
在其他的網頁我有:
<html>
<head>
<title>Test</title>
</script>
</head>
<body>
<a href="main.html#iv2">Section 2</a>
</div>
<script type="text/javascript">
if (location.hash.length > 1)
{
toggleDiv(location.hash.substring(1));
}
</script>
</body>
</html>
我喜歡這裏實現的,當我點擊「第2」的第二頁上,主頁上會用「DIV2打開「內容顯示。上面的代碼對我不起作用。
謝謝。我會試試這個,讓你知道 –