Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/438.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Jquery获取父Div元素的属性_Javascript_Jquery - Fatal编程技术网

Javascript Jquery获取父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结构

<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
   });
});