如何在jQuery中更改按钮的文本值?目前,我的按钮有“添加”作为其文本值,点击后,我希望它改变为“保存”。我尝试过下面这个方法,但到目前为止还没有成功:
$("#btnAddProfile").attr('value', 'Save');
如何在jQuery中更改按钮的文本值?目前,我的按钮有“添加”作为其文本值,点击后,我希望它改变为“保存”。我尝试过下面这个方法,但到目前为止还没有成功:
$("#btnAddProfile").attr('value', 'Save');
当前回答
在c#中更改按钮礼仪的名称。
<button type="submit" name="add" id="btnUpdate" class="btn btn-primary" runat="server" onserverclick="btnUpdate_Click">
Add
btnUpdate.**InnerText** = "Update";
其他回答
你可以使用
$("#btnAddProfile").text('Save');
虽然
$("#btnAddProfile").html('Save');
也可以,但这是一种误导(它给人的印象是你可以写什么
$("#btnAddProfile").html('Save <b>now</b>');
当然你不能
$("#btnAddProfile").html('Save').button('refresh');
这是我的工作 html:
<button type="button" class="btn btn-primary" id="btnSaveSchedule">abc</button>
js
$("#btnSaveSchedule").text("new value");
$(文档)时函数(){ $(":按钮”).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 >
如果你有按钮,这似乎工作:
<button id="button">First caption</button>
$('#button').button();//make it nice
var text="new caption";
$('#button').children().first().html(text);