我已经写了一个基本的jQuery脚本(可能对你来说是一个相当丑陋的经验丰富的jQuery兽医),但它在Firefox等工作很好(像往常一样),然后我切换到IE它在哪里没有工作。jQuery选择器不能在IE中工作
我尝试了很多不同的途径,但是从我所看到的是,IE无法获取我所要求的元素 - 我将突出显示此问题行。
// Hide all panels.
$("div.testimonial-panel").hide();
// Set the current slide as the first index
var curTest = 0;
// Show the slide with the index of curTest (this changes later)
$("div#testimonial-"+curTest).show();
// On click of any LI
$("ul#testimonial-list li").click(function() {
// If it's not the current index of curTest.
// This is to make sure nothing happens when you click the one already selected.
if($(this).index() != curTest) {
// Remove the current class off of every item to be safe, then add to current index.
$(this).siblings().removeClass("current");
$(this).addClass("current");
// Then newCurTest should equal the new index set by the click of the LI.
var newCurTest = $(this).index();
// AT THIS POINT HERE, IE SEEMS TO NOT TAKE AFFECT. THE DYNAMIC SELECTOR DOESN'T WORK FOR IE EVEN THOUGH IT RETURNS AN 'Object'
$("div#testimonial-"+curTest).hide();
$("div#testimonial-"+newCurTest).show();
curTest = newCurTest;
}
});
这里是我一起工作的HTML样本:
<div class="testimonials">
<div class="testimonial-panel" id="testimonial-0">
<h2>"Slide One"</h2>
<p><strong>Stewart Arbuckle<br /> Surveyor<br /> Jones Lang Lasalle</strong></p>
<blockquote>
<p>"The transparency that the company provides is apparent through the number of leads we recieve on a daily basis, making it a vital marketing tool for any commercial property professional."</p>
</blockquote>
</div>
<div class="testimonial-panel" id="testimonial-1">
<h2>"Slide Two"</h2>
<p><strong>Stewart Arbuckle<br /> Surveyor<br /> Jones Lang Lasalle</strong></p>
<blockquote>
<p>"The transparency that the company provides is apparent through the number of leads we recieve on a daily basis, making it a vital marketing tool for any commercial property professional."</p>
</blockquote>
</div>
<div class="testimonial-panel" id="testimonial-2">
<h2>"Slide Three"</h2>
<p><strong>Stewart Arbuckle<br /> Surveyor<br /> Jones Lang Lasalle</strong></p>
<blockquote>
<p>"The transparency that the company provides is apparent through the number of leads we recieve on a daily basis, making it a vital marketing tool for any commercial property professional."</p>
</blockquote>
</div>
<div class="testimonial-panel" id="testimonial-3">
<h2>"Slide Four"</h2>
<p><strong>Stewart Arbuckle<br /> Surveyor<br /> Jones Lang Lasalle</strong></p>
<blockquote>
<p>"The transparency that the company provides is apparent through the number of leads we recieve on a daily basis, making it a vital marketing tool for any commercial property professional."</p>
</blockquote>
</div>
<div class="testimonial-panel" id="testimonial-4">
<h2>"Slide Five"</h2>
<p><strong>Stewart Arbuckle<br /> Surveyor<br /> Jones Lang Lasalle</strong></p>
<blockquote>
<p>"The transparency that the company provides is apparent through the number of leads we recieve on a daily basis, making it a vital marketing tool for any commercial property professional."</p>
</blockquote>
</div>
<div class="testimonial-panel" id="testimonial-5">
<h2>"Slide Six"</h2>
<p><strong>Stewart Arbuckle<br /> Surveyor<br /> Jones Lang Lasalle</strong></p>
<blockquote>
<p>"The transparency that the company provides is apparent through the number of leads we recieve on a daily basis, making it a vital marketing tool for any commercial property professional."</p>
</blockquote>
</div>
<div class="testimonial-panel" id="testimonial-6">
<h2>"Slide Seven"</h2>
<p><strong>Stewart Arbuckle<br /> Surveyor<br /> Jones Lang Lasalle</strong></p>
<blockquote>
<p>"The transparency that the company provides is apparent through the number of leads we recieve on a daily basis, making it a vital marketing tool for any commercial property professional."</p>
</blockquote>
</div>
<div class="testimonial-panel" id="testimonial-7">
<h2>"Slide Eight"</h2>
<p><strong>Stewart Arbuckle<br /> Surveyor<br /> Jones Lang Lasalle</strong></p>
<blockquote>
<p>"The transparency that the company provides is apparent through the number of leads we recieve on a daily basis, making it a vital marketing tool for any commercial property professional."</p>
</blockquote>
</div>
<ul id="testimonial-list">
<li class="current"><img src="graphics/testimonial-bw.jpg" width="90" height="55" alt="" /></li>
<li><img src="graphics/testimonial-cbre.jpg" width="90" height="55" alt="" /></li>
<li><img src="graphics/testimonial-jll.jpg" width="90" height="55" alt="" /></li>
<li><img src="graphics/testimonial-canon.jpg" width="90" height="55" alt="" /></li>
<li><img src="graphics/testimonial-tlg.jpg" width="90" height="55" alt="" /></li>
<li><img src="graphics/testimonial-oxford.jpg" width="90" height="55" alt="" /></li>
<li><img src="graphics/testimonial-rapleys.jpg" width="90" height="55" alt="" /></li>
<li><img src="graphics/testimonial-nsc.jpg" width="90" height="55" alt="" /></li>
</ul>
正如你或许能看到,DIV的有一个动态内置数字追加到ID。
我使用jQuery根据LI的当前索引动态抓取它。
再一次,这一切都在Firefox中正常工作,所以我不确定我的代码是否严格错误。
任何帮助将不胜感激。我一直在寻找,并尝试几个小时才能使这个工作。 IE似乎不想挑选隐藏/显示的元素。
非常感谢, Michael。
在IE8/IE7上对我来说工作很正常:http://jsfiddle.net/gaby/PSR3Q/ – 2010-12-22 13:37:50