每当我使用该事件时,我都会收到一个 javascript 错误,指出“预期对象”指向包含 onload 事件的行。这是我的网页的简单表示。
<html>
<head>
<script type='text/javascript' src='myScript.js'>
//script containing doSomething()
</script>
</head>
<body onload = "doSomething('stringArg', 0);"> //<--does not execute, throws error, EDITED for proper quotation
//body of site
<script type='text/javascript'>
//test call
doSomething('stringArg', 0); //<--executes just fine, no errors
</script>
</body>
</html>