[英]How to load a html page from href into a div by clicking a Li inside a menu?
i have a ul menu 我有一个ul菜单
<ul>
<li>
<a href="../folder/rules.html" id="rules">rules</a>
</li>
<li>
<a href="../folder/service.html" id="service">Service</a>
</li>
</ul>
and i want when the user press on a tag the html page load on <div id=result>
that i have in bottom of this page. 我想当用户按下标签时,我在此页面底部的
<div id=result>
上加载html页面。
i try that with jquery as i found but the html in href load on new tab there is my code: 我尝试用jquery进行尝试,但是在新选项卡上的href中的html加载了我的代码:
<script src="http://code.jquery.com/jquery-1.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(funtction(){
$("#rules").click(function()
$('#result').load(rules.html);
});
$("#service").click(function(){
$('#result').load(service.html);
})
});
</script>
Read up .load()
| 阅读
.load()
| jQuery API Documentation jQuery API文档
You need to pass the paths of HTML files as string
. 您需要将HTML文件的路径作为
string
传递。
Replace 更换
$('#result').load(rules.html);
with 与
$('#result').load('../folder/rules.html');
EDIT: 编辑:
In response to your comment, try this: 为了回应您的评论,请尝试以下操作:
$("#rules").click(function(event)
$('#result').load('../folder/rules.html');
event.preventDefault(); // so that the event does not bubble up
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.