到目前为止,当您链接到一个地方时,我的HTML编码工作正常。但是,我想链接它以便您可以单击“美国”,如果您希望“北”或“南”区域下拉,则必须进一步单击。但是,当您单击“北”或“南”时,不会显示任何内容。
<script type="text/javascript">
lastone='empty';
function showIt(lyr)
{
if (lastone!='empty') lastone.style.display='none';
lastone=document.getElementById(lyr);
lastone.style.display='block';
}
</script>
<a href="JavaScript:;" onClick="showIt('divID')" ">England</a>
<div id="divID" style="display:none;">
List of stockists for England
</div>
<BR>
</script>
<a href="JavaScript:;" onClick="showIt('div1')" ">America</a>
<div id="div1" style="display:none;">
</script>
<a href="JavaScript:;" onClick="showIt('div2')" ">North</a>
<div id="div2" style="display:none;">
List of Stockists
</div>
<BR>
</script>
<a href="JavaScript:;" onClick="showIt('div3')" ">South</a>
<div id="div3" style="display:none;">
List of Stockists
</div>`<script type="text/javascript">
lastone='empty';
function showIt(lyr)
{
if (lastone!='empty') lastone.style.display='none';
lastone=document.getElementById(lyr);
lastone.style.display='block';
}
</script>
<a href="JavaScript:;" onClick="showIt('divID')" ">England</a>
<div id="divID" style="display:none;">
List of stockists for England
</div>
<BR>
</script>
<a href="JavaScript:;" onClick="showIt('div1')" ">America</a>
<div id="div1" style="display:none;">
</script>
<a href="JavaScript:;" onClick="showIt('div2')" ">North</a>
<div id="div2" style="display:none;">
List of Stockists
</div>
<BR>
</script>
<a href="JavaScript:;" onClick="showIt('div3')" ">South</a>
<div id="div3" style="display:none;">
List of Stockists
</div>`
答案 0 :(得分:0)
你编写的封闭脚本中有很多错误,这些错误永远不会被打开,而且#39;&#39;&#39;从未打开过:( onClick =&#34; showIt(&#39; div2&#39;)&#34;&#34;)例如。
如果你没有恢复&#34; lastone&#34;到&#34;空&#34;当你按下&#34; North&#34;所有&#34;美国&#34; div再次显示none,所以这个工作,你必须玩它...
<script type="text/javascript">
lastone='empty';
function showIt(lyr)
{
if (lastone !='empty') lastone.style.display='none';
lastone=document.getElementById(lyr);
lastone.style.display='block';
lastone = "empty";
}
</script>
<a href="JavaScript:;" onClick="showIt('divID')">England</a>
<div id="divID" style="display:none;">
List of stockists for England
</div>
<BR>
<a href="JavaScript:;" onClick="showIt('div1')">America</a>
<div id="div1" style="display:none;">
<a href="JavaScript:;" onClick="showIt('div2')">North</a>
<div id="div2" style="display:none;">
List of Stockists
</div>
<BR>
<a href="JavaScript:;" onClick="showIt('div3')">South</a>
<div id="div3" style="display:none;">
List of Stockists
</div>
</div>