![](/img/trans.png)
[英]How to unload the HTML page loaded in div tagafter 5 sec using Jquery?
[英]How to fix not working Jquery on a html page, that was dynamically loaded into a div?
我正在使用jQuery将html文件加载到我的index.php中。
$("#load").click(function() {
$("#content").load("/content/page.html");
});
page.html内容:
<img class="img" src="https://www.nzxt.com/uploads/download/attachment/117/Phantom-530-wallpaper-1920x1080-3.jpg"><br/>
<p style="color:green">test.html Success 1</p>
我还有一个函数,当窗口宽度改变时,它会改变图像的大小,问题是,页面加载时...图像以1920x1080px显示,但是应该是窗口宽度的80%。
function img_resize(ww,wh) {
$(".img").css("width", ww);
var img_w = $(".img").width();
$(".img").css("margin", wh);
};
因此,单击按钮后, page.html
加载到index.php div
,该图像以1920x1080px的分辨率显示,当我调整浏览器窗口的大小时,该图像缩小到窗口宽度的80%,并且不能使用css width:80 %; 为此,因为它还有其他功能可以定义图像的大小(像素),所以这仅仅是计算。 但是img_resize(ww,wh)
上方的代码正在设置/添加图像的宽度。 我尝试了mousemove,mouseover和onload,但没有任何效果。
<img class="img" src="https://www.nzxt.com/uploads/download/attachment/117/Phantom-530-wallpaper-1920x1080-3.jpg" onload="img_resize()"><br/>
<p style="color:green">test.html Success 1</p>
加载page.html
文件时,如何“启动” img_resize()
函数?
您可以使用.load()
函数的回调。
$("#load").click(function() {
$("#content").load("/content/page.html", function(response, status, xhr) {
if ( status != "error" ) {
img_resize(ww,wh);
}
});
});
请记住根据您的需要提供ww
和wh
参数。
<img class="img"
src="https://www.nzxt.com/uploads/download/attachment/117/Phantom-
530-wallpaper-1920x1080-3.jpg" style="width: 80%;"><br/>
试试这个为我工作!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.