当用户点击导航菜单项(顶部水平)时,我使用以下代码在我的主div中加载页面:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#pia").click(function(){
$("#main").load("pia.htm");
});
});
</script>
&#13;
<body itemscope itemtype="http://schema.org/SomeProducts">
<div class="myContainer">
<div class="menuIframe">
<nav>
<ul>
<li><a href="#"><b>Products</b> <img src="down_arrow.jpg"/></a>
<ul>
<li><a id="pia" href="#">Panel Instruments & Accessories</a></li>
<li><a id="stc" href="#">Sequence Timers & Controllers</a></li>
</ul>
</li>
</ul>
</nav>
</div>
<div id ="main" class="mainIframe">
<img src="13.jpg"/>
</div>
</div>
</body>
&#13;
答案 0 :(得分:0)
添加preventDefault:
$("#pia").click(function(event) {
event.preventDefault();
$("#main").load("pia.htm");
});
这将停止超链接的正常行为。
答案 1 :(得分:0)
有两种方式:
javascript:;
。 <a href="javascript:;">
。
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#pia").on('click', function(e){
$("#main").load("pia.htm");
});
});
</script>
&#13;
<body itemscope itemtype="http://schema.org/SomeProducts">
<div class="myContainer">
<div class="menuIframe">
<nav>
<ul>
<li><a href="javascript:;"><b>Products</b> <img src="down_arrow.jpg"/></a>
<ul>
<!-- make href attribute value javascript:; -->
<li><a id="pia" href="javascript:;">Panel Instruments & Accessories</a></li>
<li><a id="stc" href="javascript:;">Sequence Timers & Controllers</a></li>
</ul>
</li>
</ul>
</nav>
</div>
<div id ="main" class="mainIframe">
<img src="13.jpg"/>
</div>
</div>
</body>
&#13;