Javascript <form> 标签上的 Onload 事件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29750738/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 03:55:06 来源:igfitidea点击:
Onload event on <form> tag
提问by Sudarshan Taparia
I want a JavaScript function to execute when the page loads.
我想要一个 JavaScript 函数在页面加载时执行。
I added an onloadattribute to my <form>tag, but the alertis not executed.
我onload向我的<form>标签添加了一个属性,但alert没有执行。
What am I doing wrong?
我究竟做错了什么?
<form name=myfm method=post action=quiz.php onload = alert('hello')>
回答by TheSk8rJesus
try adding the onloadto the bodytag
尝试添加onload到body标签
<body onload="alert('Hello World')">
回答by Careen
// javaScript
window.onload = function{
alert("loaded");
}
// jquery
$(document).ready(function() {
$("#div-id").click(function(){
alert("the page is loaded");
});
});

