您的位置:首页 > Web前端 > JQuery

26个Jquery使用小技巧

2013-11-19 23:54 483 查看
下面列出了一些Jquery使用技巧。比如有禁止右键点击、隐藏搜索文本框文字、在新窗口中打开链接、检测浏览器、预加载图片、页面样式切换、所有列等高、动态控制页面字体大小、获得鼠标指针的X值Y值、验证元素是否为空、替换元素、延迟加载、验证元素是否存在于Jquery集合中、使DIV可点击、克隆对象、使元素居中、计算元素个数、使用Google主机上的Jquery类库、禁用Jquery效果、解决Jquery类库与其他Javascript类库冲突问题。



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).

11. 获得鼠标指针XY值

Want to know where your mouse cursor is?

12. 验证元素是否为空

This will allow you to check if an element is empty.

13. 替换元素

Want to replace a div, or something else?

14. jQuery延时加载功能

Want to delay something?

15. 移除单词功能

Want to remove a certain word(s)?

16. 验证元素是否存在于jquery对象集合中

Simply test with the .length property if the element exists.

17. 使整个DIV可点击

Want to make the complete div clickable?

18. ID与Class之间转换.

当改变Window大小时,在ID与Class之间切换

19. 克隆对象

Clone a div or an other element.

20. 使元素居屏幕中间位置

Center an element in the center of your screen.

21. 写自己的选择器

Write your own selectors.

22. 统计元素个数

Count an element.

23. 使用自己的 Bullets

Want to use your own bullets instead of using the standard or images bullets?

24. 引用Google主机上的Jquery类库

Let Google host the jQuery script for you. This can be done in 2 ways.

25. 禁用Jquery(动画)效果

Disable all jQuery effects

26. 与其他Javascript类库冲突解决方案

To avoid conflict other libraries on your website, you can use this jQuery Method, and assign a different variable name instead of the dollar sign.

英文原文:26-cool-and-usefull-jquery-tips-tricks-solutions
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: