javascript - 即使我将脚本标记放在正文标记的结尾上方,页面也仅在单击弹出窗口后才加载
问题描述
即使我将我的脚本标签放在正文标签的结尾上方,页面也只有在单击确定后才会加载页面。我该怎么办?
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<h1>this is for beginners javascript</h1>
<div> <p>this is a div</p> </div>
<script src="js_notes.js"></script>
</body>
</html>
js_notes.js 仅包含下面给出的这一行
alert('hello world');
解决方案
你想让我做什么 ?加载 html 时将始终读取 js 文件。如果您只想在执行事件时加载弹出窗口(例如单击 div :这是一个 div),只需使用 onclick 函数。
在您的 js_notes.js 中:
function showpopup() {
alert('hello');
}
如果您只想等待页面加载,可以使用 window.onload 或计时器 (setTimeout(showpopup, 1000))
在您的 html 文件中:
<div onclick='showpopup()'>Text Content Here</div>
推荐阅读
- xml - 如何在scala中单独处理大xml有效负载的块
- javascript - Converting Function Base Component into Class Base Component
- python - 如何以编程方式获取 waitress.queue:Task depth
- flutter - Flutter:无法使用 rootBundle 读取本地 json 文件
- c# - .Net Api - 与无效嵌套路由匹配的父路由
- r - 使用刻度颜色离散的 ggplot 中颜色的错误匹配
- elasticsearch - 在 ElasticSearch 中的多个字段中搜索返回的结果比预期的要多
- django - Django频道将用户添加到组
- javascript - 在createlice中将redux调度反应到reducer不起作用
- python - numpy中如何计算数组中的数组?