简体   繁体   English

Jquery $('#someID> div')。each(function(){..})在IE中不起作用

[英]Jquery $('#someID > div').each(function(){..}) not working in IE

i don't face this problem while working on localhost only when I access the page using the ip address of my system this happens and it only happens with IE!! 只有当我使用我的系统的IP地址访问页面时,我才会在使用localhost时遇到此问题,这种情况只会发生在IE! (works on all other browsers) (适用于所有其他浏览器)

by the way i'm using Tomcat V6.0.0.29, IE8 顺便说一句,我使用的是Tomcat V6.0.0.29,IE8

I tried debugging the JS code using IE developer tools debugger, ofcourse when I open using http://localhost:8080/ everything works perfectly fine, but when I use http://myIP:8080/ this loop is giving a problem :- 我尝试使用IE开发工具调试器来调试JS代码,当我使用http://localhost:8080/打开时,一切都运行得很好,但是当我使用http://myIP:8080/这个循环给出了一个问题: -

$('#someId > div').each(function(){...}); 

As in this loop doesn't run at all, it just kind of skips it. 由于在这个循环中根本没有运行,它只是跳过它。 I have checked the IDs they are fine moreover its working in localhost why should it give a problem when I access it using my IP? 我已经检查了它们的ID,而且它在localhost中的工作原因为什么当我使用我的IP访问它时它会出现问题?

Note :- a. 注意: - a。 (correction) The problem is only there in IE7, it works perfectly in IE8. (更正)问题只出现在IE7中,它在IE8中完美运行。

b. As it turns out something weird is happening! 事实证明发生了一些奇怪的事情! i'm using IE8 when i open this webpage using localhost the developer tools shows its working in IE8 standards but when i use the IP address to access this page the developer tools shows its working in IE7 standards. 当我使用localhost打开此网页时,我正在使用IE8,开发人员工具显示其工作在IE8标准,但当我使用IP地址访问此页面时,开发人员工具显示其工作在IE7标准。 When i changed the standards to IE8 it worked (using the IP address)! 当我将标准更改为IE8时,它工作(使用IP地址)!

c. C。 But the problem is why the hell is it not working with IE7!! 但问题是为什么它不适合IE7! As in everything works except the loop mentioned above. 因为除了上面提到的循环之外,一切都有效。

Finally i came to know what was causing the problem in IE7. 最后我才知道IE7中导致问题的原因。 Consider the below situation:- 考虑以下情况: -

<div id="div1">abc
          <div id="div2">def
                   <div>hjs</div>
                   <div>zyx</div>
          </div>
          <div id="div3">xsj
                   <div>ask</div>
                   <div>iue</div>
          </div>
</div>

The jquery i had written for traversing these divs was something like 我为遍历这些div而编写的jquery就是这样的

$("#divId > div").each(function(){..}); $(“#divId> div”)。each(function(){..});

Now for the first level div that is traversing the divs directly inside the div with id "div1" worked perfectly in IE7, but when i did something like:- 现在为第一级div正在遍历div内部的div,id为“div1”在IE7中完美运行,但当我做了类似的事情: -

$("#div2 > div").each(function(){..}); $(“#div2> div”)。each(function(){..});

This worked in all browsers (even in IE8!!) but not in IE7. 这适用于所有浏览器(即使在IE8中),但在IE7中却没有。 This is because apparently IE7 requires the exact child selector for divs. 这是因为显然IE7需要div的精确子选择器。 So for IE7 something like this needs to be written:- 所以对于IE7,需要写下这样的东西: -

$("#div1 > #div2 > div").each(function(){..}); $(“#div1> #div2> div”)。each(function(){..});

for traversing the divs inside the div with id "div2" 用id“div2”遍历div内的div

So the problem was cause just by my lack of knowledge about IE7!! 所以问题是因为我对IE7缺乏了解! sorry n thanks guys! 对不起,谢谢你们!

The culprit being IE it could turn out something as evil as the browser not caching the page when loaded from localhost, but reading it from cache when using the ip. 罪魁祸首是IE,它可能会变成一种邪恶的东西,因为浏览器在从localhost加载时没有缓存页面,而是在使用ip时从缓存中读取它。 Make sure you load the page to empty cache from your ip. 确保加载页面以从ip清空缓存。

This may due to the group policy of your company for forcing Intranet sites using a specific version of IE in compatibility mode. 这可能是由于贵公司的组策略在兼容模式下使用特定版本的IE强制Intranet站点。 I experienced exactly the same issue when I introducing some IE10+ Javascript libraries to my page. 当我向我的页面介绍一些IE10 + Javascript库时,我遇到了完全相同的问题。

IE兼容性视图设置

To work around this you can either ask your company IT for changing the policy or force the browser to not using a compatibility view with the following tag. 要解决此问题,您可以要求您的公司IT部门更改策略,或强制浏览器不使用带有以下标记的兼容性视图。

<meta http-equiv="X-UA-Compatible" content="IE=Edge" />

More details for this tag can be found with the topic below. 有关此标记的更多详细信息,请参阅以下主题。

StackOverflow - Force IE compatibility mode off using tags StackOverflow - 使用标签强制关闭IE兼容模式

Check to see if your script is loaded when using your IP address. 使用您的IP地址时,请检查您的脚本是否已加载。 Sometimes browsers don't load scripts on special situations (for example when you want to load a script from an http source into an https page). 有时浏览器不会在特殊情况下加载脚本(例如,当您要将脚本从http源加载到https页面时)。 Also you should check IE's security configuration. 您还应该检查IE的安全配置。
To check whether your script is loaded and executed or not, simply put an alert('loaded') statement at the beginning of your code. 要检查脚本是否已加载和执行,只需在代码的开头添加一个alert('loaded')语句。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM