通过jQuery向输入字段添加文本
我需要添加一个文本输入文本字段后,点击一个按钮。button类总是相同的(“.button”),所以我认为我需要使用“$(this)”,但我不知道如何使用它 我的代码是: HTML: 注意:)尝试替换通过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(
.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')