Javascript Jquery获取父Div元素的属性
我有一个重复的div结构Javascript Jquery获取父Div元素的属性,javascript,jquery,Javascript,Jquery,我有一个重复的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="butto
<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>
我想清除Paret类DIV的输入元素的值,但它不能获取每个函数中的输入元素
$('.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);
});
});
parent
是目标元素的类值,因此需要将其与类选择器一起使用,如。parent
$('.clear').bind("click", function (e) {
$(this).closest('.parent').find('input').each(function (index) {
console.log(this);
});
});
试试这个
$('.clear').bind("click", function (e){
$(this).closest('.parent').find('input').each(function (index){
$(this).val(''); // to clear the value
});
});
$('.clear').bind("click", function (e){
$(this).closest('.parent').find('input').each(function (index){
$(this).val(''); // to clear the value
});
});