如果我的屏幕宽度小于 960 像素,如何让 jQuery 做一些事情?无论我的窗口大小如何,下面的代码都会触发第二个警报:
if (screen.width < 960) { alert('Less than 960'); } else { alert('More than 960'); }
使用 jQuery 获取窗口的宽度。
if ($(window).width() < 960) { alert('Less than 960'); } else { alert('More than 960'); }