开发者

append string to textbox contents?

开发者 https://www.devze.com 2023-02-07 16:08 出处:网络
pretty simple, I have buttons but i want to add their value to a textbox when they are clicked, ho开发者_高级运维w would i go about doing this in jQuery? They are all numbers and their cant be more th

pretty simple, I have buttons but i want to add their value to a textbox when they are clicked, ho开发者_高级运维w would i go about doing this in jQuery? They are all numbers and their cant be more than 10 in the textbox.


pretty easy task with jQuerys .val()help method:

$('button').click(function(event) {
    $('input:text').val(function(index, val) {
        return val + event.target.value;
    });
});

Demo: http://www.jsfiddle.net/QFm7K/


or

$('button').click(function() {
    $('textarea')[0].value += $(this).val();
});


use jquery .val to set the text box value , it should do it

http://api.jquery.com/val/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号