如何在jQuery中更改按钮的文本值?目前,我的按钮有“添加”作为其文本值,点击后,我希望它改变为“保存”。我尝试过下面这个方法,但到目前为止还没有成功:
$("#btnAddProfile").attr('value', 'Save');
如何在jQuery中更改按钮的文本值?目前,我的按钮有“添加”作为其文本值,点击后,我希望它改变为“保存”。我尝试过下面这个方法,但到目前为止还没有成功:
$("#btnAddProfile").attr('value', 'Save');
当前回答
如果你有按钮,这似乎工作:
<button id="button">First caption</button>
$('#button').button();//make it nice
var text="new caption";
$('#button').children().first().html(text);
其他回答
要更改按钮的文本,只需执行下面的jQuery行 为
<输入类型=“按钮”值=“XYZ”id=“btnaddprofil”>
use
$("#btnAddProfile").val('Save');
而对于
<button id='btnAddProfile'>XYZ</button>
使用这个
$(“#btnAddProfile”).html(“保存”);
你可以这样使用:
$('#your-button').text('New Value');
你也可以添加额外的属性,像这样:
$(this).text('New Value').attr('disabled', true).addClass('bt-hud').unbind('click');
$("#btnAddProfile").click(function(){
$("#btnAddProfile").attr('value', 'Save');
});
$("#btnviewdetails").click(function(){
if($(this).val()!="hide details"){
$("#detailedoutput").show();
$(this).val('hide details');
}else{
$("#detailedoutput").hide();
$(this).val('view more details');
}
});
$( "#btnAddProfile" ).on( "click",function(event){
$( event.target ).html( "Save" );
});