jQuery加载IE FF和Chrome [英] jquery load IE FF and Chrome

查看:88
本文介绍了jQuery加载IE FF和Chrome的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道为什么当我添加由.Load()方法加载的页面时,Chrome无法正确解析页面

I was wondering why Chrome doesnt parse a page correctly when I add a page loaded by the .Load() method

我集成了一个带有完整html,head和body标签的页面,它只是忽略了除我的内容以外的所有内容.使得无法集成jquery脚本...

I integrate a page with full html, head and body tags and it just ignores everything there except my content. Making it impossible to integrate a jquery script...

我在俯视什么吗?在load()ing时,Chrome浏览器会过滤掉html,head和body标签吗?

Am i overlooking something? Does chrome filter out the html, head and body tags when load()ing?

第二个问题...是否需要使用完整的html,在集成页面上放置正文标记,还是我可以在正文标记和其中的脚本之间传递所有内容?

2nd question... Is it needed to use full html, head an body tagging on the integrated page, or can i just pass everything between the body tag and but the script in there?

触发颜色框的元素:

<a class="teaminfo cboxElement" href="news/teaminfo.htm">Lees verder</a>

已加载的页面. (简而言之)

the Page thats loaded. ( in short)

<head>
<title></title>
<link type="text/css" href="/style/style.css" rel="stylesheet"  />
<link type="text/css" media="screen" rel="stylesheet" href="/style/style.css" />

<meta name="keywords" content="" />
<script src="/js/jquery-1.4.1.min.js" type="text/javascript"></script>
<script  src="/js/jquery.colorbox-min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(document).ready(function()
    {
        $(".teaminfo").colorbox();
    });
</script>

第3和第4个问题:如果我在页面的body元素中放置一个脚本,它将使用调用页面的头脚本,并在w3c上验证吗?

3rd and 4th question: If i put a script in the body element of the page, will this use the calling page head scripts, and will it validate at w3c?

推荐答案

您可以通过以下方法解决此问题:脚本剥离(已更新为与您发布的代码相匹配):

You can do this as a work-around for the script stripping (updated to match your posted code):

如果您的电话是这样:

$("#myElem").load("myPage.htm");

您可以尝试添加回调(如果传递参数,则回调是第三个参数 ):

You can try with a callback added (if you pass params, callback is the third param):

$("#myElem").load("myPage.htm", function(resp) {
  $('.teaminfo', resp).colorbox();
});

现在将<script src="/js/jquery.colorbox-min.js" type="text/javascript"></script>放在主页上,而不是现在.只会在响应内的.teaminfo元素上调用.colorbox();.

Just place the <script src="/js/jquery.colorbox-min.js" type="text/javascript"></script> in your main page instead now. This will call .colorbox(); on the .teaminfo elements only within the response when it comes in.

对于另一个问题,是的,您只能传递体内的东西并看到相同的结果.

For the other question, yes, you can pass what's in the body only and see the same result.

这篇关于jQuery加载IE FF和Chrome的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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