页面加载后在图像上运行 jquery
我编写了一个 jQuery 图像调整大小脚本,当使用处理程序 $('img').click (function(){
) 单击图像时,该脚本可以正常工作。(参见示例 此处)
但是我想将其设置为在页面加载后立即运行,但是 $('img' ).load(function(){
不起作用。(参见此处示例)我假设这是因为它在 DOM 加载后运行脚本而不是图像,但老实说我不知道。
I have written a jQuery image resize script that works fine when the images are clicked using the handler, $('img').click (function(){
. (see example here)
However I want to set it to run as soon as the page is loaded but $('img').load(function(){
doesn't work. (see example here) I'm assuming it's because it's running the script after the DOM has loaded but not the images. But If I'm honest I don't know.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你可以这样做:
You could do:
在正常的
$(document).ready()
函数下运行它怎么样?这将在页面完全加载时运行。How about just running it under the normal
$(document).ready()
function? This will run when the page is fully loaded.您不能使用 $(document).ready 因为它只考虑 DOM 已加载。你需要使用
You can't use $(document).ready because that only takes into account that the DOM is loaded. You need to use