将JS代码,插入到head区域,即可在网页打开时执行。
示例:
<html><head><title>test</title></head>
<script>
alert("已经开始执行函数!")
</script>
<body></body>
</html>
<html><body>
<button id="button" onclick="sendMsg()">自动执行</button>
</body>
</html>
<script type="text/javascript">
window.onload = function(){
var button = document.getElementById('button')
button.click()//执行执行点击按钮
}
var sendMsg = function(){
alert('按钮已点击执行')
}
</script>