Un botón muestra la hora local del usuario cuando se hace clic. Luego tengo otro botón que detiene el reloj. Estoy tratando de deshabilitar "mostrar hora local" cuando se hace clic en el botón "detener hora".
<button id="start" onclick="showTime()" >Show Local showTime</button> <button id="stop" onclick="myStop()">Stop Time</button>
Este es mi código en HTML
He intentado esto para mi document.getElementById(start).disabled = true; document.getElementById(stop).removeAttribute('disabled')
Intenté esto
function showTime() { document.getElementById("start").disabled = true; } function myStop() { document.getElementById("stop").disabled = false; }Ninguno de estos tiene trabajos para deshabilitar el otro botón. Se permite hacer clic en ambos.
Por lo que tengo la pregunta, debe deshabilitar un botón cuando hace clic en el otro botón. Publicaré una respuesta que hará el trabajo.
function showTime() { document.getElementById("stop").disabled = !document.getElementById("stop").disabled; } function myStop() { document.getElementById("start").disabled = !document.getElementById("start").disabled; } Al hacer clic en el botón show local time ,
stop time stop time está habilitadostop time stop time está deshabilitado Al hacer clic en el botón de stop time ,
show local time si show local time está habilitadoshow local time si show local time está deshabilitado