我得到了这个带有标签按钮的输入字段
<input id="demooutput" type="text" size="15" value="My Text" name="demo" />
<span class="demooutput">
<a href="#" class="button orange"> A</a>
<a href="#" class="button orange"> B</a>
<a href="#" class="button orange"> C</a>
<a href="#" class="button orange"> D</a>
<a href="#" class="button orange"> E</a>
</span>
使用此 jQuery 代码,我将值添加到输入
$('.demooutput a').click(function(){
$('#demooutput').val($(this).html());
return false;
});
但是每次点击按钮我都会清除现有的值
我想将按钮中的值添加到输入中的现有值
例如我想要谁
My Text A (by click on A)
My Text A B (by click on A and B)
My Text B C E (by click on B, C and E)
and so on..
请参阅 JSFIDDLE 上的演示
最佳答案
$('#demooutput').val($('#demooutput').val() + $(this).html());
关于jquery - 单击时向输入字段的现有值添加附加值 - jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17908244/