且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我如何使用jQuery将某些内容附加到表单元素的值,而不是更改它?

更新时间:2023-09-14 12:21:52

$('#foo').val($('#foo').val() + 'something');

(当然,您可以并且应该缓存该元素).

(Of course you can and should cache the element).

另一种方式(非常jQuery风格):

Another way (very jQuery style):

$('#foo').val(function(){
    return this.value + "something";
});