如何在jQuery中更改按钮的文本值?目前,我的按钮有“添加”作为其文本值,点击后,我希望它改变为“保存”。我尝试过下面这个方法,但到目前为止还没有成功:

$("#btnAddProfile").attr('value', 'Save');

当前回答

    $( "#btnAddProfile" ).on( "click",function(event){
    $( event.target ).html( "Save" );
});

其他回答

$("#btnAddProfile").click(function(){
    $("#btnAddProfile").attr('value', 'Save');
 });

你可以使用

$("#btnAddProfile").text('Save');

虽然

$("#btnAddProfile").html('Save');

也可以,但这是一种误导(它给人的印象是你可以写什么

$("#btnAddProfile").html('Save <b>now</b>');

当然你不能

你可以这样使用:

$('#your-button').text('New Value');

你也可以添加额外的属性,像这样:

$(this).text('New Value').attr('disabled', true).addClass('bt-hud').unbind('click');

$(“#btnAddProfile”).text(“保存”);

完全正确,这对我来说很管用;

    $('#btnAddProfile').bind('click',function(){
    $(this).attr('value','save');
})

你确定Jquery是可用的,你的代码是在正确的地方?