Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/464.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.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更改输入值_Javascript_Jquery_Html - Fatal编程技术网

Javascript 使用该类下的jquery更改输入值

Javascript 使用该类下的jquery更改输入值,javascript,jquery,html,Javascript,Jquery,Html,jQuery: html 隐藏 我的目标是,如果我单击“clickhere”类,“abc”类下的内容将被隐藏,客户在这些输入框中添加的任何内容都将被清除 同一html在同一表单上多次使用。这就是为什么要使用“$(this)”。 有解决办法吗?我做错了什么? 提前感谢。您需要使用来设置值,jQuery方法通常会返回一个jQuery对象,而不是dom元素引用,因此您将无法正确调用.value <div class="row"> <div class='abc'>

jQuery:

html


隐藏
我的目标是,如果我单击“clickhere”类,“abc”类下的内容将被隐藏,客户在这些输入框中添加的任何内容都将被清除

同一html在同一表单上多次使用。这就是为什么要使用“$(this)”。
有解决办法吗?我做错了什么?
提前感谢。

您需要使用来设置值,jQuery方法通常会返回一个jQuery对象,而不是dom元素引用,因此您将无法正确调用
.value

<div class="row">
  <div class='abc'>
     <input type='text' class='unknown' />
  </div>
  <div class="clickhere">hide</div>
</div>

所以

<div class="row">
  <div class='abc'>
     <input type='text' class='unknown' />
  </div>
  <div class="clickhere">hide</div>
</div>
$(this).closest('.row').find('.abc input').val('');
$('.clickhere').click(function (e) {
    e.preventDefault();
    //cache the value of .row since it is used multiple times
    var $row = $(this).closest('.row');
    $row.children('.abc').hide(); // working
    $row.find('.abc input').val('');
});