如何在窗口调整大小的jQuery调用函数? [英] How to call a function in jQuery on window resize?

查看:69
本文介绍了如何在窗口调整大小的jQuery调用函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的代码:

I've this code:

<script>
            $(document).ready(function larg(){
            var larghezza = $(document).width();
            $("p.width").text("The width for the " + larghezza + 
                " is px.");
            });

            $(window).resize(function() {
            larg(); 
            });
            </script>

我想在窗口大小上调用函数larg,但它不起作用。 。
如何做到这一点??

I would like to call the function "larg" on window resize, but it doesn't work.. How to do that??

谢谢

Thanks

推荐答案

你不能用这种方式声明函数,就像这样使用它。

You can't declare functions that way, use it like this.

<script>
 $(document).ready(larg);

 $(window).resize(larg);

 function larg(){
  var larghezza = $(document).width();
  $("p.width").text("The width for the " + larghezza + " is px.");
 }
</script>

编辑:改变了一下代码,谢谢评论者

changed code a bit, thanks commenters

这篇关于如何在窗口调整大小的jQuery调用函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆