首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在前两个不包含选中单选按钮后隐藏div

在前两个不包含选中单选按钮后隐藏div
EN

Stack Overflow用户
提问于 2013-04-26 17:05:15
回答 5查看 251关注 0票数 0

JSFiddle

在前两个迷你齿轮div之后,如果其中包含的单选按钮没有被选中,我希望它隐藏div,但是它只是在前2个之后隐藏所有div(第5个被选中,所以它不应该隐藏在这个例子中)。

jQuery :

代码语言:javascript
复制
$("div.mini-cog").slice(2).each(function () {

    // this is hiding Radio Button Question 5, but since its checked i want it to appear
    // $(this).find(':input').not(':checked').parent('div').hide();
});

HTML :

代码语言:javascript
复制
<form method="post" action="">
    <div id="question-1" class="mini-cog">
         <h4>Radio Button Question 1</h4>

        <label for="radio-choice-1-a" class="checkbox inline">Choice 1
            <input type="radio" name="radio-choice-1" id="radio-choice-1-a" tabindex="2" value="choice-1" />
        </label>
        <label for="radio-choice-1-b" class="checkbox inline">Choice 2
            <input type="radio" name="radio-choice-1" id="radio-choice-1-b" tabindex="3" value="choice-2" />
        </label>
    </div>
    <div id="question-2" class="mini-cog">
         <h4>Radio Button Question 2</h4>

        <label for="radio-choice-2-a">Choice 1</label>
        <input type="radio" name="radio-choice-2" id="radio-choice-2-a" tabindex="2" value="choice-1" />
        <label for="radio-choice-2-b">Choice 2</label>
        <input type="radio" name="radio-choice-2" id="radio-choice-2-b" tabindex="3" value="choice-2" />
    </div>
    <div id="question-3" class="mini-cog">
         <h4>Radio Button Question 3</h4>

        <label for="radio-choice-3-a">Choice 1</label>
        <input type="radio" name="radio-choice-3" id="radio-choice-3-a" tabindex="2" value="choice-1" />
        <label for="radio-choice-3-b">Choice 2</label>
        <input type="radio" name="radio-choice-3" id="radio-choice-3-b" tabindex="3" value="choice-2" />
    </div>
    <div id="question-4" class="mini-cog">
         <h4>Radio Button Question 4</h4>

        <label for="radio-choice-4-a">Choice 1</label>
        <input type="radio" name="radio-choice-4" id="radio-choice-4-a" tabindex="2" value="choice-1" />
        <label for="radio-choice-4-b">Choice 2</label>
        <input type="radio" name="radio-choice-4" id="radio-choice-4-b" tabindex="3" value="choice-2" />
    </div>
    <div id="question-5" class="mini-cog">
         <h4>Radio Button Question 5</h4>

        <label for="radio-choice-5-a">Choice 1</label>
        <input type="radio" name="radio-choice-5" id="radio-choice-5-a" tabindex="2" value="choice-1" checked="checked" />
        <label for="radio-choice-5-b">Choice 2</label>
        <input type="radio" name="radio-choice-5" id="radio-choice-5-b" tabindex="3" value="choice-2" />
    </div>
</form>
EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2013-04-26 17:16:50

-试试这个:- http://jsfiddle.net/adiioo7/e755d/61/

联合材料:-

代码语言:javascript
复制
$("div.mini-cog").slice(2).each(function () {
    if($(this).find(':input').not(':checked').length!=1)
        $(this).hide();
});
票数 0
EN

Stack Overflow用户

发布于 2013-04-26 17:13:25

试一试:

代码语言:javascript
复制
if ($(this).find(':input:checked').val() === undefined) $(this).hide();

jsFiddle实例

票数 1
EN

Stack Overflow用户

发布于 2013-04-26 17:16:23

像这样的事怎么样:

代码语言:javascript
复制
$("div.mini-cog:gt(1)").filter(function () {
    if($(this).find('input:not(:checked)').length > 1)
        return this;
}).hide();

演示:http://jsfiddle.net/dirtyd77/e755d/63/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16241698

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档