Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.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
通过jQuery向输入字段添加文本_Jquery_Input_Click_This - Fatal编程技术网

通过jQuery向输入字段添加文本

通过jQuery向输入字段添加文本,jquery,input,click,this,Jquery,Input,Click,This,我需要添加一个文本输入文本字段后,点击一个按钮。button类总是相同的(“.button”),所以我认为我需要使用“$(this)”,但我不知道如何使用它 我的代码是: HTML: 注意:)尝试替换.parent()input type=“text”似乎是.previouselement的同级。按钮元素 $(this).prev("input[type=text]").val("hhh"); 使用最近的 $(this).closest('input[type="text"]').val(

我需要添加一个文本输入文本字段后,点击一个按钮。button类总是相同的(“.button”),所以我认为我需要使用“$(this)”,但我不知道如何使用它

我的代码是:

HTML:

注意:)

尝试替换
.parent()
input type=“text”
似乎是
.previouselement的同级
。按钮
元素

  $(this).prev("input[type=text]").val("hhh");
使用最近的

$(this).closest('input[type="text"]').val('hhh')

$(this.prev().val('hhh')谢谢。工作完美;)
  $(this).prev("input[type=text]").val("hhh");
$(this).closest('input[type="text"]').val('hhh')