0

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>

It works in firefox, but not in chrome and IE. Can anyone help me?

4

1 回答 1

3

为什么不

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为该区域内加载的所有链接设置一个类,#content并处理所有这些链接。


可能是它不起作用的原因是您单击得太快并且尚未加载 jquery 吗?

于 2012-06-30T22:19:29.370 回答