type link eventos botones boton javascript jquery html button ui-automation

javascript - link - Haga clic en un elemento de botón en la carga de la página



input type button onclick (4)

Estoy intentando hacer clic automáticamente en un botón para iniciar una función cuando se carga la página html. He intentado document.getElementById(''watchButton'').click y parece que no funciona, no se hace clic en el botón. ¿Alguna sugerencia?

<div class="content"> <div class="action-area ch30"> <button class="button dh" id="watchButton">Start Geolocation Watch</button> <button class="button dh" id="refreshButton" >Refresh Geolocation</button> </div>

El javascript:

run:function() { var that = this; document.getElementById("watchButton").addEventListener("click", function() { that._handleWatch.apply(that, arguments); }, false); document.getElementById("refreshButton").addEventListener("click", function() { that._handleRefresh.apply(that, arguments); }, false); },

¡Gracias!


Lo pondría en document.ready (para que no se active hasta que se cargue DOM) y utilice la sintaxis de jQuery:

$(function() { $(''#watchButton'').click(); });

http://jsfiddle.net/isherwood/kVJVe/

Aquí está el mismo violín usando la sintaxis de jQuery: http://jsfiddle.net/isherwood/kVJVe/4

Dicho esto, ¿por qué no solo nombras tu función y la llamas directamente?


Sería click() no click

document.getElementById("watchButton").click();

Debería llamarlo onload o después de que la función se haya ejecutado


intentar disparar

<script> $(document).ready(function() { $("#watchButton").trigger(''click''); }); </script>


document.getElementById("studyOne").click(); $("#studyOne").trigger(''click'');

Pon esto en la función de carga. Funcionó para mí