Jquery常用功能
jQuery 1.4给开发者带来了很多值得兴奋的新特性,同时使用jQuery的人也越来越多,为了方便大家对jQuery的使用,下面列出了一些jQuery使用技巧。比如有禁止右键点击、隐藏搜索文本框文字、在新窗口中打开链接、检测浏览器、预加载图片等等。具体如下:
禁止右键点击
- $(document).ready(function(){
- $(document).bind("contextmenu",function(e){
- return false;
- });
- });
隐藏搜索文本框文字
- $(document).ready(function() {
- $("input.text1").val("Enter your search text here");
- textFill($('input.text1'));
- });
- function textFill(input){ //input focus text function
- var originalvalue = input.val();
- input.focus( function(){
- if( $.trim(input.val()) == originalvalue ){ input.val(''); }
- });
- input.blur( function(){
- if( $.trim(input.val()) == '' ){ input.val(originalvalue); }
- });
- }
在新窗口中打开链接
- $(document).ready(function() {
- //Example 1: Every link will open in a new window
- $('a[href^="http://"]').attr("target", "_blank");
- //Example 2: Links with the rel="external" attribute will only open in a new window
- $('a[@rel$='external']').click(function(){
- this.target = "_blank";
- });
- });
- // how to use
- <A href="http://www.opensourcehunter.com" rel=external>open link</A>
检测浏览器
注: 在版本jQuery 1.4中,$.support 替换掉了$.browser 变量。
- $(document).ready(function() {
- // Target Firefox 2 and above
- if ($.browser.mozilla && $.browser.version >= "1.8" ){
- // do something
- }
- // Target Safari
- if( $.browser.safari ){
- // do something
- }
- // Target Chrome
- if( $.browser.chrome){
- // do something
- }
- // Target Camino
- if( $.browser.camino){
- // do something
- }
- // Target Opera
- if( $.browser.opera){
- // do something
- }
- // Target IE6 and below
- if ($.browser.msie && $.browser.version <= 6 ){
- // do something
- }
- // Target anything above IE6
- if ($.browser.msie && $.browser.version > 6){
- // do something
- }
- });
预加载图片
- $(document).ready(function() {
- jQuery.preloadImages = function()
- {
- for(var ; i").attr("src", arguments[i]);
- }
- };
- // how to use
- $.preloadImages("image1.jpg");
- });
页面样式切换
- $(document).ready(function() {
- $("a.Styleswitcher").click(function() {
- //swicth the LINK REL attribute with the value in A REL attribute
- $('link[rel=stylesheet]').attr('href' , $(this).attr('rel'));
- });
- // how to use
- // place this in your header
- <LINK href="default.css" type=text/css rel=stylesheet>
- // the links
- <A class=Styleswitcher href="#" rel=default.css>Default Theme</A>
- <A class=Styleswitcher href="#" rel=red.css>Red Theme</A>
- <A class=Styleswitcher href="#" rel=blue.css>Blue Theme</A>
- });
原文地址:http://www.cnblogs.com/xiaopin/archive/2010/11/13/1876366.html
Jquery常用功能的更多相关文章
- JQuery常用功能的性能优化
使用最佳选择器 通常比较常用的选择器有以下几个: 1.ID选择器 $("#id") 2.标签选择器 $("td") 3.类选择器 $(".target ...
- 从零开始学习jQuery (十) jQueryUI常用功能实战
一.摘要 本系列文章将带您进入jQuery的精彩世界, 其中有很多作者具体的使用经验和解决方案, 即使你会使用jQuery也能在阅读中发现些许秘籍. 本文是实战篇. 使用jQueryUI完成制作网站 ...
- JQuery常用函数及功能
JQuery常用函数及功能小结 来源:http://blog.csdn.net/screensky/article/details/7831000 1.文档加载完成执行函数 $(document).r ...
- [转]WebPack 常用功能介绍
概述 Webpack是一款用户打包前端模块的工具.主要是用来打包在浏览器端使用的javascript的.同时也能转换.捆绑.打包其他的静态资源,包括css.image.font file.templa ...
- JQuery常用实用的事件[较容易忽略的方法]
JQuery常用实用的事件 注:由于JQuery片段较多就没有用插入代码文本插入,请见谅!JQuery 事件处理ready(fn)代码: $(document).ready(function(){ ...
- JQuery常用API 核心 效果 JQueryHTML 遍历 Event事件
JQuery 常用API 参考资料:JQuery 官网 jQuery API 中文文档 核心 jQuery 对象 jQuery() 返回匹配的元素集合,无论是通过在DOM的基础上传递的参数还是创建 ...
- 非常好用的弹出层 layer,常用功能demo,快速上手!
功能强大,实用,操作方便,文档齐全. 参数灵活,丰富.可以作为开发项目的公共模块,多处使用.老文档地址:http://layer.layui.com/api.html 已经停止维护 新文档地址:htt ...
- js与jquery常用数组方法总结
昨天被问数组方法的时候,问到sort()方法是否会改变原来的数组.本来我猜是不会,也是这么说,马上我又觉得,知识这种东西,不确定的时候直接说不确定或不知道就好,只是凭借着不确定的猜测或者是记忆,害人害 ...
- Atiit 常见功能 常用功能与模块的最快速解决方案
Atiit 常见功能 常用功能与模块的最快速解决方案 一.大力使用第三方API接口 一.导出excel jquery.table2excel 二.Form表单验证,使用h5验证属性 验证发生在form ...
随机推荐
- __attribute__机制介绍 (转)
1. __attribute__ GNU C的一大特色(却不被初学者所知)就是__attribute__机制. __attribute__可以设置函数属性(Function Attribute).变量 ...
- HTML快速参考
HTML 模版 html> <head> <meta charset="utf-8"/> <title>html template< ...
- 网上下载的 java开源项目 如何 打jar包
目前很多java开源项目(例如qlexpress)只提供了源码,没有提供jar,下面提供maven打jar包的方法. 1.进入qlexpress下载后源代码所在的目录,此目录应包含pom.xml,如下 ...
- jvm内存GC详解
一.相关概念 a. 基本回收算法 1. 引用计数(Reference Counting) 比较古老的回收算法.原理是此对象有一个引用,即增加一个计数,删除一个引用则减少一个计数.垃圾回收时,只用收 ...
- 写一段方便的SQL 循环查每一天的数据
declare @recd int,@i int,@a int,@count int,@day1 date,@day2 date,@days int set @day1='2014-8-24' set ...
- Day 3 @ RSA Conference Asia Pacific & Japan 2016 (afternoon)
13.30 hrs Keynote Security in the World-Sized Web Bruce Schneier,Chief Technology Officer, Resili ...
- java接口相关例题
java接口相关习题 interface Graphics{ //接口里面只能用抽象方法 public abstract double area(); }//设置 平面类class Plan ...
- Win8控制面板快捷键
Win8系统相比我们已经熟悉的Win7与XP系统有着一些特殊的变化,导致很多初次使用Win8系统的朋友感觉有点吃力,随着Win8系统即将于几天后正式发布,下面本文与大家分享大家比较关心的Win8控制面 ...
- 将内容重定向到剪切板(clip.exe)
Add-Type -Assembly PresentationCore[Windows.Clipboard]::SetText("abc中文def")先用 $output | Ou ...
- 【OpenCV十六新手教程】OpenCV角检测Harris角点检测
本系列文章由@浅墨_毛星云 出品.转载请注明出处. 文章链接:http://blog.csdn.net/poem_qianmo/article/details/29356187 作者:毛星云(浅墨) ...