HTML:
<div class="quiz-template">
<span class="question">1. What is the first word in the first chapter of the series?</span>
<div class="image-container">
<img src="img2/q1.png" />
</div>
<div class="answer-container">
<div class="a-choice1">
<input type="radio" name="qa1" value="0" />
<label for="btn1"></label>
<span>The</span>
</div>
<div class="a-choice1">
<input type="radio" name="qa1" value="0" />
<label for="btn2"></label>
<span>Albus</span>
</div>
<div class="a-choice1">
<input type="radio" name="qa1" value="0" />
<label for="btn3"></label>
<span>Number</span>
</div>
<div class="a-choice1">
<input type="radio" name="qa1" value="1" />
<label for="btn4"></label>
<span>Mr.</span>
</div>
</div>
<div class="result-container" id="r1">
<!--
<span class="tic mark">✓</span>
<span class="cross mark">X</span>
-->
<span class="result-text"></span>
<span class="result-description">
The first sentence reads, “Mr. and Mrs. Dursley, of number four, Privet Drive, were proud to say that they were perfectly normal, thank you very much.”
</span>
</div>
</div>我试图通过这个函数显示显示隐藏的结果容器类:none;
$('.a-choice1').click(function () {
$(this).parent().siblings('.results-container').show("fast");
});但不起作用。我的遍历代码有什么问题?另外,是否有一种方法可以使选择器内的值动态,这样我就可以执行一个循环?有点像:
$(this).parent().siblings('div[id=r '+N+']').show("fast");其中N是一个整数,可以增加值以访问ids r1、r2、r3.诸若此类?
发布于 2014-07-22 21:50:41
试试这个:
$('.a-choice1').find("input[type=radio]").click(function () {
$(this).parents(".answer-container").next(".result-container").show("fast");
});parents() (带有选择器):http://api.jquery.com/parents/
next() (带有选择器):http://api.jquery.com/next/
这是给你的一把小提琴:
http://jsfiddle.net/rePgM/
要执行一个循环,应该如下所示:
$(this).parent().siblings('.result-container').each(function(e, i){
$(this).show("fast"); //$(this) now refers to each instance of the parent's siblings
});这也消除了您发送ID号的需要。
发布于 2014-07-22 21:39:44
尝试查找法
$(this).parent().find('div#r'+N).show("fast");https://stackoverflow.com/questions/24898280
复制相似问题