我已經寫了一個基本的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