我想在html页面加载时自动点击一个按钮以启动一个函数。我尝试了document.getElementById('watchButton').click
,但它似乎不起作用,按钮没有被点击。有什么建议吗?
<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>
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);
},
谢谢!
<head>
中,但它仍然无法正常工作。 - user2883848<script type="text/javascript"> $(document).ready(function() { $(function() { $('#watchButton').click(); }); }); </script>
- user2883848run:
。那是干什么用的? - isherwood