加载外部的.htm用JavaScript到一个div
问题描述:
我试图加载在我的主网页外部.htm文件到一个div,我已经使用了以下code:
I am trying to load an external .htm file to a div on my main page, and I have used the following code:
<a href="#file.htm" onclick="$('#content').load('file.htm')">Link</a>
它工作在Firefox,但不是在Chrome和IE浏览器。谁能帮我?
It works in firefox, but not in chrome and IE. Can anyone help me?
答
为什么不
HTML
<a href="file.htm" class="ajax">Link</a>
和增加剧本
<script type="text/javascript">
$(function(){
$('.ajax').click(function(e){
e.preventDefault();
$('#content').load( this.href );
});
});
</script>
这种方式,您可以设置一个类 AJAX
到加载#内容
区域内,它的所有链接他们处理所有的..
this way you can set a class ajax
to all the links that load inside the #content
area and it handle all of them..
这可能是因为它不工作的原因是,你点击太快而jQuery是没有装?
Could it be that the reason it does not work is that you click too soon and the jquery is not yet loaded ?