我正在用較小設備的全屏覆蓋替換模型窗口。假設 $(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 關注
- 221 瀏覽
添加回答
舉報
0/150
提交
取消