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

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

当前回答

$(文档)时函数(){ $(":按钮”).click(函数(){ $ (p) .toggle (); if (this.value=="Add") this。value = "保存"; 其他的。value = "添加"; }); }); <!DOCTYPE html > < html > < >头 < script src = " https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js " > < /脚本> < / >头 <身体> <input type='button' value='Add' id='btnAddProfile'> <p>这是一个内容很少的段落 <p>这是另一小段 < /身体> < / html >

其他回答

$("#btnviewdetails").click(function(){
    if($(this).val()!="hide details"){
        $("#detailedoutput").show();
        $(this).val('hide details');
    }else{
        $("#detailedoutput").hide();
        $(this).val('view more details');
    }

});

你需要执行。button("refresh")

HTML:

<button id='btnviewdetails' type='button'>SET</button>

JS :

$('#btnviewdetails').text('Save').button("refresh");

你给你的按钮一个类而不是一个id?试试下面的代码

$(".btnSave").attr('value', 'Save');

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

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

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

你可以这样使用:

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

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

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