我有一个重复的div结构
<div class="parent">
<input type="text" name="name" class="name" value="test">
<input type="hidden" name="id" class="id" value="123">
<span class="btns">
<button name="btn_clr" class="clear" type="button" value="Clear"></button>
</span>
</div>
在Jquery中我有一个用于清除按钮的onclick函数
$('.clear').bind("click", function (e){
$(this).closest('.parent').find('input').each(function (index){
console.log(this);
});
});
我想清除Paret Class DIV的输入元素的值,但是没有在每个函数中获取INPUT元素
答案 0 :(得分:0)
尝试.parent()
喜欢
$('.clear').bind("click", function (e){
$(this).closest('.btns').parent().find('input').each(function (index){
console.log(this);
});
});
甚至尝试
$('.clear').bind("click", function (e){
$(this).closest('.parent').find('input').each(function (index){
console.log(this);
});
});
答案 1 :(得分:0)
parent
是目标元素的类值,因此您需要将其与类.parent
$('.clear').bind("click", function (e) {
$(this).closest('.parent').find('input').each(function (index) {
console.log(this);
});
});
答案 2 :(得分:0)
试试这个,
$('.clear').bind("click", function (e){
$(this).closest('.parent').find('input').each(function (index){
$(this).val(''); // to clear the value
});
});