tiene texto saber obtener elemento div con cambiar boton atributo jquery jquery-ui

saber - obtener el texto de un button jquery



¿Cómo cambiar el texto de un botón en jQuery? (21)

¿Cómo cambias el valor de texto de un botón en jQuery? Actualmente, mi botón tiene "Agregar" como valor de texto y, al hacer clic en él, quiero que cambie a "Guardar". He intentado este método a continuación, pero hasta ahora sin éxito:

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


¿Le has dado a tu botón una clase en lugar de una identificación? prueba el siguiente código

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


Cambio de nombre de la etiqueta del botón en C #.

<button type="submit" name="add" id="btnUpdate" class="btn btn-primary" runat="server" onserverclick="btnUpdate_Click"> Add

btnUpdate.**InnerText** = "Update";


Depende del tipo de botón que estés usando

<input type=''button'' value=''Add'' id=''btnAddProfile''> $("#btnAddProfile").attr(''value'', ''Save''); //versions older than 1.6 <input type=''button'' value=''Add'' id=''btnAddProfile''> $("#btnAddProfile").prop(''value'', ''Save''); //versions newer than 1.6 <!-- Different button types--> <button id=''btnAddProfile'' type=''button''>Add</button> $("#btnAddProfile").html(''Save'');

Tu botón también podría ser un enlace. Tendrá que publicar algunos HTML para una respuesta más específica.

EDITAR : esto funcionará suponiendo que lo hayas envuelto en una llamada .click() , por supuesto

EDIT 2 : las versiones más nuevas de jQuery (desde> 1.6) usan .prop lugar de .attr

EDICIÓN 3 : Si está utilizando la interfaz de usuario de jQuery, debe usar el método de DaveUK (a below ) para ajustar la propiedad de texto


Es un trabajo para mi HTML:

<button type="button" class="btn btn-primary" id="btnSaveSchedule">abc</button>

js

$("#btnSaveSchedule").text("new value");


Esto debería funcionar:

$("#btnAddProfile").prop(''value'', ''Save''); $("#btnAddProfile").button(''refresh'');


La forma correcta de cambiar el texto del botón si fue "abotonado" usando JQuery es usar el método .button ():

$( ".selector" ).button( "option", "label", "new text" );


Necesitas hacer .button("refresh")

HTML :

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

JS :

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


Para botones creados con .Button () en jQuery ........

Mientras que las otras respuestas cambiarán el texto, arruinarán el estilo del botón, resulta que cuando se representa un botón jQuery, el texto del botón se anida dentro de un espacio, por ejemplo

<button id="thebutton"> <span class="ui-button-text">My Text</span> </button>

Si elimina el intervalo y lo reemplaza con texto (como en los otros ejemplos), perderá el intervalo y el formato asociado.

¡Así que realmente necesita cambiar el texto dentro de la etiqueta SPAN y NO el BOTÓN!

$("#thebutton span").text("My NEW Text");

o (si, como yo, se está haciendo en un evento de clic)

$("span", this).text("My NEW Text");


Para cambiar el texto de un botón, simplemente ejecute la siguiente línea de jQuery para

<input type=''button'' value=''XYZ'' id=''btnAddProfile''>

utilizar

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

mientras que para

<button id=''btnAddProfile''>XYZ</button>

utilizar esta

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


Puedes usar

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

a pesar de que

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

funcionaría igual de bien, pero es engañoso (da la impresión de que podría escribir algo como

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

pero claro que no puedes


Puedes usar algo como esto:

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

También puedes agregar propiedades extra como esta:

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


Si has pulsado tu botón, esto parece funcionar:

<button id="button">First caption</button> $(''#button'').button();//make it nice var text="new caption"; $(''#button'').children().first().html(text);



eso es exactamente correcto, esto funciona para mí;

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

¿Está seguro de que Jquery está disponible y que su código está en el lugar correcto?


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


$(document).ready(function(){ $(":button").click(function(){ $("p").toggle(); if (this.value=="Add") this.value = "Save"; else this.value = "Add"; }); });

<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> </head> <body> <input type=''button'' value=''Add'' id=''btnAddProfile''> <p>This is a paragraph with little content.</p> <p>This is another small paragraph.</p> </body> </html>


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


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


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


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


document.getElementById(''btnAddProfile'').value=''Save'';