jQuery:如何组合两行代码(使用相同的目标)
我是jQuery新手,正在尝试将以下两行代码组合起来,因为它们都指向同一个div(jQuery:如何组合两行代码(使用相同的目标),jquery,jquery-selectors,Jquery,Jquery Selectors,我是jQuery新手,正在尝试将以下两行代码组合起来,因为它们都指向同一个div($(this).nest('div.col-9')。nextAll('div.hiddenDiv')),我还有其他类似的场景,这也会减少代码: $(this).closest('div.col-9').nextAll('div.hiddenDiv').find('input, select, textarea').removeProp('checked').removeProp('selected').not(':
$(this).nest('div.col-9')。nextAll('div.hiddenDiv')
),我还有其他类似的场景,这也会减少代码:
$(this).closest('div.col-9').nextAll('div.hiddenDiv').find('input, select, textarea').removeProp('checked').removeProp('selected').not(':button, :checkbox, :hidden, :radio, :reset, :submit').val('');
$(this).closest('div.col-9').nextAll('div.hiddenDiv').hide();
上面写的方式很好,所以我可能是用错误的方式组合的。我尝试了以下两种方法,但都失败了:
$(this).closest('div.col-9').nextAll('div.hiddenDiv').find('input, select, textarea').removeProp('checked').removeProp('selected').not(':button, :checkbox, :hidden, :radio, :reset, :submit').val('').end().hide();
$(this).closest('div.col-9').nextAll('div.hiddenDiv').find('input, select, textarea').removeProp('checked').removeProp('selected').not(':button, :checkbox, :hidden, :radio, :reset, :submit').val('').hide();
有人能告诉我我做错了什么吗
多谢各位,
Mike您应该首先调用
$.fn.hide()
方法,然后查找子项并执行所需的操作
$(this)
.closest('div.col-9')
.nextAll('div.hiddenDiv')
.hide() //<=----------------------- Call Hide method
.find('input, select, textarea')
.removeProp('checked')
.removeProp('selected')
.not(':button, :checkbox, :hidden, :radio, :reset, :submit')
.val('');
$(此)
.最近('div.col-9')
.nextAll('div.hiddenDiv')
.hide()//