加载外部的.htm用JavaScript到一个div [英] Loading an external .htm with javascript into a div

查看:86
本文介绍了加载外部的.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 ?

这篇关于加载外部的.htm用JavaScript到一个div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆