如何获得有关元素加载的警报消息?
How get an alert message on element load?
我想在加载弹出窗口后收到提醒消息。
它适用于 body 标签,但在此 div 中没有响应。
<script>
function myFunction() {
alert("I am an alert box!");
}
</script>
<html>
<body>
<div class="modal fade flat-popupform" id="popup_10_jan" onload="myFunction()">
<img src="<?php echo base_url(); ?>resources/images/events/jan-10-2019/1.jpeg" alt="Events" style="max-width:100%;">
</div>
</body>
</html>
onload 事件属性不适用于 div 标记。
唯一支持的标签是 <body>, <frame>, <frameset>, <iframe>, <img>, <input type="image">, <link>, <script> and <style>
请参阅 https://www.w3schools.com/tags/ev_onload.asp 了解更多信息。
我能想到的最简单的解决方案是将脚本标签和 javascript 代码(在脚本标签内)紧跟在 div 之后。
<html>
<body>
<div class="modal fade flat-popupform" id="popup_10_jan">
<script>
alert("I am an alert box!");
</script>
<img src="<?php echo base_url(); ?>resources/images/events/jan-10-2019/1.jpeg" alt="Events" style="max-width:100%;">
</div>
</body>
</html>
脚本应在 div 加载后立即执行,因为它位于 div 内。那应该可以解决您的问题。
我想在加载弹出窗口后收到提醒消息。 它适用于 body 标签,但在此 div 中没有响应。
<script>
function myFunction() {
alert("I am an alert box!");
}
</script>
<html>
<body>
<div class="modal fade flat-popupform" id="popup_10_jan" onload="myFunction()">
<img src="<?php echo base_url(); ?>resources/images/events/jan-10-2019/1.jpeg" alt="Events" style="max-width:100%;">
</div>
</body>
</html>
onload 事件属性不适用于 div 标记。
唯一支持的标签是 <body>, <frame>, <frameset>, <iframe>, <img>, <input type="image">, <link>, <script> and <style>
请参阅 https://www.w3schools.com/tags/ev_onload.asp 了解更多信息。
我能想到的最简单的解决方案是将脚本标签和 javascript 代码(在脚本标签内)紧跟在 div 之后。
<html>
<body>
<div class="modal fade flat-popupform" id="popup_10_jan">
<script>
alert("I am an alert box!");
</script>
<img src="<?php echo base_url(); ?>resources/images/events/jan-10-2019/1.jpeg" alt="Events" style="max-width:100%;">
</div>
</body>
</html>
脚本应在 div 加载后立即执行,因为它位于 div 内。那应该可以解决您的问题。