当前位置:Gxlcms > JavaScript > jQuery实用技巧必备(上)

jQuery实用技巧必备(上)

时间:2021-07-01 10:21:17 帮助过:16人阅读

这篇文章主要总结了经典且实用的jQuery代码开发技巧。可以帮助大家快速开发,感兴趣的小伙伴们可以参考。具体如下:

1. 禁止右键点击

2. 隐藏搜索文本框文字
Hide when clicked in the search field, the value.(example can be found below in the comment fields)

3. 在新窗口中打开链接

XHTML 1.0 Strict doesn't allow this attribute in the code, so use this to keep the code valid.

4. 检测浏览器
注: 在版本jQuery 1.4中,$.support 替换掉了$.browser 变量

5. 预加载图片
This piece of code will prevent the loading of all images, which can be useful if you have a site with lots of images.

6. 页面样式切换

7. 列高度相同
如果使用了两个CSS列,使用此种方式可以是两列的高度相同。

8. 动态控制页面字体大小
用户可以改变页面字体大小

9. 返回页面顶部功能
For a smooth(animated) ride back to the top(or any location).

10. 获得鼠标指针XY值
Want to know where your mouse cursor is?

11.返回顶部按钮
你可以利用 animate 和 scrollTop 来实现返回顶部的动画,而不需要使用其他插件。

改变scrollTop 的值可以调整返回距离顶部的距离,而 animate 的第二个参数是执行返回动作需要的时间(单位:毫秒)。

今天为大家先介绍一部分jQuery技巧,更多相关教程请访问jQuery视频教程!

人气教程排行