将子类添加到子元素输入值为空的父元素?

时间:2018-05-09 13:39:54

标签: javascript jquery html css

点击按钮#btn-modal-clear时,我想选择一个类并将其添加到li,其中sub-child输入为空(value="")。我该怎么做?

HTML:

<li>...<li> 
<li>
    <a class="myCheckboxLink" tabindex="0">
        <span class="myCheckboxSpan">
            <i class="fa fa-check fa-check-checkbox" aria-hidden="true"></i>
        </span>
        <label class="radio">
            <input value="" type="radio">Name
        </label>
    </a>
</li>
<li>...<li>     

JS:

$('#btn-modal-clear').on('click', function() {  
    $('.select-name').multiselect('select', ['']);
    $('.select-name').multiselect('updateButtonText');

    ... .addClass("active"); 

});

结果应该是:

HTML:

<li>...<li> 
<li class="active">
    <a class="myCheckboxLink" tabindex="0">
        <span class="myCheckboxSpan">
            <i class="fa fa-check fa-check-checkbox" aria-hidden="true"></i>
        </span>
        <label class="radio">
            <input value="" type="radio">Name
        </label>
    </a>
</li>
<li>...<li> 

小提琴:https://jsfiddle.net/ewm9pbqv/

2 个答案:

答案 0 :(得分:1)

在这种情况下,您可以class Fruit(BaseModel): fruit_id= CharField() name = Charfield() color= ForeignKeyField(column_name='color', field='color', model=Color, null=True) class Meta: table_name = 'fruit' .filter()一起使用:

.addClass()

答案 1 :(得分:1)

试试这个

$('li input[value=""]').closest("li").addClass('active');