我正在用较小设备的全屏覆盖替换模型窗口。假设 $(window).hide() 不必要地将该窗口保留在内存中,我正在尝试使用 $(window).unload(),但它没有按预期工作。我使用一个 PHP 变量作为脚本名称,因为不同的脚本将使用此实用程序。在进一步探索时,我发现 unload() 已被弃用,并且可能一开始并不打算以这种方式使用。除了 $(window).hide 之外,我不知道还有什么选择。这是完整的代码<?php session_start(); $Script = $_REQUEST[Script];?><!DOCTYPE html><html> <head> <script type="text/javascript" src="js/jquery-3.4.1.min.js"></script> <style type="text/css"> body {width:100%; padding:0; margin:0; background-color:#FFFFFF;} .Leave {position:absolute; top:20px; right:20px;} </style> </head> <body> <img class="Leave" src="images/CloseButton2.png" alt="close"> <div id="ScreenOverlay"></div> <script> $(document).ready(function() { $("#ScreenOverlay").load("<?PHP echo($Script); ?>", function(response, status, xhr) { if(status == "error") { console.log(msg + xhr.status + " " + xhr.statusText); } }); $(".Leave").click(function() { $(window).unload(); }); }); </script> </body></html>
1 回答

哆啦的时光机
TA贡献1779条经验 获得超6个赞
预期的行为是什么?您不会通过调用卸载从内存中卸载窗口。卸载需要一个事件处理程序
也许你想要
$(".Leave").click(function() $(window).close() });
假设你自己从同源脚本打开了窗口
没有 window.hide 这样的东西
如果您只想卸载的内容,$("#ScreenOverlay")
则执行$("#ScreenOverlay").empty()
或$("#ScreenOverlay").remove()
- 1 回答
- 0 关注
- 201 浏览
添加回答
举报
0/150
提交
取消