标签:jquery

浏览模式: 标准 | 列表 | 图文
JS取当时间的一个很妖的方法

JS取当时间的一个很妖的方法

关于new Date().getTime()的简写方式.

原文来自cssrain,只取了其中的一小部分。http://www.cssrain.cn/demo/3/newDate.html

小结:
(1)getTime(new Date.getTime 方法)
返回指定的 Date 对象自 1970 年 1 月 1 日午夜(通用时间)以来的毫秒数。当比较两个或更多个 Date 对象时,使用此方法表示某一特定时刻。
返回值类型:Number -- 一个整数。

(2)
function now(){
return +new Date;
}
jQuery 源代码里就是使用的 +new Date ;

(3)
用来判断 google 浏览器:
if( !isNaN(Date.parse("1970.01.01")) ){
alert("This is Google Chrome!");
}else{
alert("This is NOT!");
}
结果:1和2的结果是一样的。但这个number是13位的number,和PHP中的时间戳并非同一个意义
祝贺:微软也开源 将采用jQuery JavaScript库

祝贺:微软也开源 将采用jQuery JavaScript库

微软和诺基亚正式宣布支持开源的 jQuery JavaScript库,另外,微软还称他们将把jQuery作为Visual Studio工具集的一部分。他将提供包括jQuery的智能提示,代码片段,示例,文档编制等内容在内的功能。微软和诺基亚将长期成为jQuery的用户成员,其他成员还有Google, Intel, IBM, Intuit, 路透社等。

好东西,不得不贴,继续上传两个文件

好东西,不得不贴,继续上传两个文件

今天看到一个好东西,是jquery的API,这次的API不是象以前那样用XML的,也不是那种根据官方的数据简单的汉化而来的,这次。。。。阿健同学编译成了CHM文件(虽然以前的也是CHM文件),并且有索引和搜索功能哦。只是由于编译方式的问题吧?不支持中文搜索,不过也总比以前那种纯粹的一个页面来的爽。OH YEAH。。。

剩下一个嘛,就是传统的CSS手册了,这个手册估计只要是WEB开发人员就会人手一份,苏沈小雨同学实在是太让人尊敬了,估计国内开发人员提到CSS手册,都会说,哦,就是那个苏沈小雨的呀。。。

不多说,放上链接。黑黑
注意:jqueryApi文件打开后会生成一个chw的文件,如果你看不顺眼可以每次删掉

为JQuery的cycle插件作图片自动缩放

为JQuery的cycle插件作图片自动缩放

function showImg(){
pw = parseInt( $(this).parent().css('width') );
ph = parseInt( $(this).parent().css('height') );
showImage = new Image();
showImage.src = $(this).children('a').children('img').attr('src');
sw = showImage.width;
sh = showImage.height;
//原先这些sw是直接用 $(this).width()来判断,但实际上很多时间都取回的是pager里面的图片大小属性,或者取回来有不正常的时候,这是cycle的BUG,没有时间却验证了,因此,只有用Image类来进行处理,这样取回来的就是图片真正的大小
idx = $('#bigPic li').index( $(this) );
alert(showImage.src+' - '+sw+' - '+sh);
if (sw > pw || sh > ph){
if (sw > sh ){
sh = Math.floor(sh * ( pw / sw ));
sw = pw-10;
}else {
sw = Math.floor(sw * ( ph / sh ));
sh = ph-10;
}
//实在不知道这里为什么会多出16px,如果不减6,就会每次缩小
//这里的长宽比例会不正确。。。
$(this).children('a').children('img').css({'width': sw,'height':sh,'paddingTop':3});
}
if (sh <= ph){
$(this).css('marginTop',(ph - sh)/2).css('verticalAlign','middle');
}
if (sw <= pw){
$(this).css('marginLeft' , (pw - sw)/2).css('textAlign','center');
}
if( idx == 0 ){
$('#thumbnail a').trigger('click');
}
}

Mark it ,and update it on work time...

jquery radio,checkbox,select操作

jquery radio,checkbox,select操作

本来不想转这个,可实在是太常用了。。
还是先转载一下,原文:http://www.cnblogs.com/kaixin110/archive/2008/03/25/1120888.html

获取一组radio被选中项的值
var item = $('input[@name=items][@checked]').val();
获取select被选中项的文本
var item = $("select[@name=items] option[@selected]").text();
select下拉框的第二个元素为当前选中值
$('#select_id')[0].selectedIndex = 1;
radio单选组的第二个元素为当前选中值
$('input[@name=items]').get(1).checked = true;

获取值:

文本框,文本区域:$("#txt").attr("value");
多选框checkbox:$("#checkbox_id").attr("value");
单选组radio: $("input[@type=radio][@checked]").val();
下拉框select: $('#sel').val();

控制表单元素:
文本框,文本区域:$("#txt").attr("value",'');//清空内容
$("#txt").attr("value",'11');//填充内容

多选框checkbox: $("#chk1").attr("checked",'');//不打勾
$("#chk2").attr("checked",true);//打勾
if($("#chk1").attr('checked')==undefined) //判断是否已经打勾

单选组radio: $("input[@type=radio]").attr("checked",'2');//设置value=2的项目为当前选中项
下拉框select: $("#sel").attr("value",'-sel3');//设置value=-sel3的项目为当前选中项
$("<option value='1'>1111</option><option value='2'>2222</option>").appendTo("#sel")//添加下拉框的option
$("#sel").empty();//清空下拉框

[转载]超强大的jquery formValidator

jQuery formValidator表单验证插件开源了!!含API帮助、源码、示例

升级记录


2.0
这次又做了一次比较大的调整:增加了FunctionValidator这种校验方式,现在你可以调用外部函数了;调整了内部部分算法;
你打开下载压缩包里的index.html,将会看到全新的演示。
1、增加FunctionValidator校验方式。作用:你可以用外部函数对表单元素进行校验和处理,返回true/false表示校验是否成功;返回字符串表示自定义错误信息,校验失败;如果没有返回值表示处理过程,校验成功。范例代码如下:
$("#sfzh").formValidator({onshow:"请输入15或18位的身份证",onfocus:"输入15或18位的身份证",oncorrect:"输入正确"}).FunctionValidator({fun:isCardID});
fun这个参数给你的函数传递了2个参数(该表单元素的值,表单元素element) 。具体情况,请看API帮助文档
2、当你调用PageIsValid的时候,如果未校验通过,则给onError传递2个参数(第一个校验没通过元素的错误信息,第一个校验没通过元素element)。范例代码如下:
$.formValidator.initConfig({onError:function(msg){alert(msg)}});
3、AjaxValidator校验方式增加一个配置参数buttons(你点提交的按钮(组)jQuery对象)。作用:当你触发了ajax校验,buttons里对应的按钮(组)就会灰掉,一直等待服务器返回数据为止。范例代码如下:
$("#test1").formValidator({...}).InputValidator({...}).AjaxValidator({
url : "Default.aspx",
datatype : "json",
success : function(data){...},
buttons: $("#button_id"),
error: function(){alert("服务器没有返回数据,可能服务器忙,请重试");},
onerror : "该用户名不可用,请更换用户名重新",
onwait : "正在对用户名进行合法性校验,请稍候..."
});
4、由于增加了自定义错误信息的功能,为了跟FunctionValidator校验方式里"fun"函数返回意义统一,更改了formValidator里的onvalid参数返回的意义,给大家带来不便请谅解。返回true/false表示校验是否成功;返回字符串表示自定义错误信息,校验失败;如果没有返回值表示处理过程,校验成功。


1.3
由于工作忙,网友提了很多珍贵的意见,到现在才更新插件,真的对不住!这次修改了几处不合理的地方。
特别增加了DefaultPassed函数,并且调整了表单元素校验的顺序。
1、增加DefaultPassed函数,作用:如果你的表单元素有默认值,而且是合法的,你可以通过这个,设置默认校验通过,示例代码如下:
$("#sex").formValidator({onshow:"请选择你的性别",onfocus:"没有第三种性别了,你选一个吧",oncorrect:"输入正确",defaultvalue:"1"}).InputValidator({min:1,max:1,onerror:"性别忘记选了,请确认"}).DefaultPassed();
2、修正了showalert模式下,只有值发生改变的时候才触发校验
3、修改了表单提交的时候,表单元素校验的顺序,现在按照表单元素的流顺序进行校验
4、demo1里集成了datatimemask插件,具体应用,请见“出生日期”的代码
5、避免了插件与别的javascript类库的$符号的冲突
6、修改了api帮助文档


1.2.1
修复表单元素额外校验失败还会提交得bug,即formValidator里的onvalid属性

1.2.0
这个版本,内部函数做了比较大的调整,开放了更多的函数提供给大家使用,使插件灵活性更大
特别申明:请保留插件的版权申明,谢谢
1、修改插件文件名为:formValidator.js ; 对应的正则表达式的库也被命名为formValidatorRegex.js。
2、SelectValidator被合并到InputValidtor中去,请大家赶紧修改,语法兼容,只要替换名称即可。
3、因为InputValidtor合并了SelectValidator,所以API帮助里列举了InputValidtor各属性能起作用的各种表单类型
4、开放3个公共函数,这些函数跟你的配置相关:
SetFailState function("tipid","显示的信息"),在showword模式下,如果你的额外校验没有通过,你可以通过它来设置成失败信息和状态。
IsOneValid function("表单元素id"),主要来判断单个表单元素是否验证通过。
GetLength function("表单元素id"),判断表单元素的选择长度(个数)。
checkbox或radiobutton表示(同组)选择的个数。
select表示选择的selectedIndex值。
其它的表示字符长度。
5、formValidator里的onvalid属性,增加了返回值,即插件校验成功后,你还可以额外校验。例子请参见demo1里的【额外校验】
return true表示这个表单元素校验成功
return false表示这个表单元素校验失败
错误信息,你可以通过SetFailState函数要写
6、修复在firefox下,长度验证出错的bug。发现jQuery1.2不支持这么写:$("#textarea").attr("type")


1.1.2
1、为AjaxValidator添加一个addidvalue属性(是否自动添加id和值到url参数后面)
为了修复AjaxValidator在配置信息的时候,取不到运行时候值的bug
插件将自动在url后面自动添加,形式为"id=value"的网页参数
在服务器端,你可以通过Request.querystring["id"]来取值
具体演示请看demo1里的用户名输入和Default.aspx


1.1.1版本
1、紧急修复AjaxValidator校验状态出错,以及显示状态的bug
2、调整了内部OneIsValid和formValidator函数的算法,使判断更加合理、有效

1.1 功能比较全的一个版本.
1、开放AjaxValidator表单验证,主要对$.ajax()的调用,具体演示请看demo1里的用户名输入和Default.aspx
用户名在服务器端的校验,我是用了随机数取模,但是每次运行返回要么都是偶数要么都是奇数(不知道什么问题)。
先是长度校验,再是格式校验,最后才是服务器端校验
2、修正AjaxValidator校验状态出错,以及显示状态的问题bug。
3、修正对AjaxValidator的api帮助。
4、修正内部几个函数的一些bug。
5、未了适应AjaxValidator,调整formValidator初始化的一部分功能。

1.0.3
1、把InputValidator的属性defaultvalue移到formValidator下。
目前defaultvalue属性只支持input和select两种tag
2、增加demo1里的范例内容,增加了性别的选择和默认值的设置(性别、学历、爱国、国家区号、你的描述)。
3、增加RegexValidator的一个属性:datatype,支持外置正则表达式的枚举类型,具体请见demo3.html
你可以额外包含这个js文件,定义一个数据类型,你可以自由的修改里面的名称和对应的值
var regexEnum =
{
intege:"^([+-]?)\\d+$" //整数
}
如何调用范例:$("#zs").formValidator({onshow:"请输入整数",oncorrect:"谢谢你的合作,你的整数正确"}).RegexValidator({regexp:"intege",datatype:"enum",onerror:"整数格式不正确"});
4、修正自动纠错的一个bug
5、修正了api帮助文档


1.0.2版本
1、为formValidator增加tipid属性。
主要为了解决多个表单元素共用一个TIP的问题,提示错误的原则:后面的成功或失败信息都不覆盖前面的失败信息
针对这个属性,已经更新了demo1和源码,具体请看范例
2、修正了部分bug和api说明文档疏漏的地方


1.0.1版本
1、修改formValidator下的属性onvalid
增加2个参数,参数1:对象本身 参数2:值。主要是校验通过后,你还希望执行一些操作,你可以方便的取到对象和值
2、去掉InputValidator、SelectValidator、CompareValidator、RegexValidator、AjaxValidator下的onvalid属性
写文档的时候太过匆忙,所以属性加多了,帮助文档和源码都已经修正
3、为formValidator增加属性:automodify,默认值:false。
这个属性只要针对,如果你输入的是非法的,离开焦点的时候将自动恢复上次的值,并且先都有提示,showword模式的提示变成onshow状态
4、为formValidator增加onfocusevent和onblurevent
因为jQuery的事件注册是覆盖的,不是attachEvent追加的,所以再托管出这两个被插件霸占住的事件onfocus和onblur
onfocusevent:获得焦点的时候,处理系统自动处理的代码后,继续你希望再执行的代码
onblurevent:失去焦点的时候,处理系统自动处理的代码后,继续你希望再执行的代码
5、提交验证过程中,如果没有验证通过,则第一个出错的获得焦点
6、申明一点:RegexValidator采用的是显式构造函数new RegExp("pattern"[,"flags"]); 由于Javascript 中'\' 被用作转义字符,所以在使用显示构造函数构造实例对象的时候,需要使用'\\' 代替'\'

1、插件应用效果图浏览

效果图1:


效果2:



2、jQuery pageValidator插件主要功能

1、2种错误提示模式:文字提示、窗口提示
2、呈现时的提示
3、可以为空,空时的提示
4、获得焦点提示
5、发生不同种错误,给出不同的提示
6、可以为空,不为空时要检验控制
7、长度控制、值比较
8、范围控制
9、2个对象比较控制
10、选择个数控制
11、Ajax读取数据
12、正则表达式控制
13、同个页面,你可以划分多个校验组,每个组的校验都是互不影响的
14、单个对象或者整个校验组验证完成、或者出错,有额外的回调函数提供




下载 http://www.cnblogs.com/Files/wzmaodong/formValidator2.0.rar



5、示例代码

<script type="text/javascript">
$(document).ready(function(){
$.formValidator.initConfig({onError:function(){alert("校验没有通过,具体错误请看错误提示")}});
$("#test1").formValidator({onshow:"请输入用户名",onfocus:"用户名至少6个字符,最多10个字符",oncorrect:"恭喜你,你输对了"}).InputValidator({min:6,max:10,onerror:"你输入的用户名非法,请确认"});
$("#test2").formValidator({onshow:"请选择你的兴趣爱好(至少选择3个,最多选择5个)",onfocus:"你至少选择3个,最多选择5个",oncorrect:"恭喜你,你选对了"}).InputValidator({min:3,max:5,onerror:"你选的个数不对(至少选择3个,最多选择5个)"});
$("#test3").formValidator({onshow:"请选择你的兴趣爱好(至少选一个)",onfocus:"你至少选择1个",oncorrect:"恭喜你,你选对了"}).InputValidator({min:1,onerror:"你选的个数不对"});
$("#xueli").formValidator({onshow:"请选择你的学历",onfocus:"学历必须选择",oncorrect:"谢谢你的配合"}).SelectValidator({onerror: "你是不是忘记选择学历了!"});
$("#password1").formValidator({onshow:"请输入密码",onfocus:"两次密码必须一致哦",oncorrect:"密码一致"}).InputValidator({min:1,onerror:"密码不能为空,请确认"}).CompareValidator({desID:"password2",operateor:"=",onerror:"2次密码不一致,请确认"});
$("#nl").formValidator({onshow:"请输入的年龄(1-99岁之间)",onfocus:"只能输入1-99之间的数字哦",oncorrect:"恭喜你,你输对了"}).InputValidator({min:1,max:99,type:"value",onerror:"年龄必须在1-99之间,请确认"});
$("#aiguo").formValidator({onshow:"爱国的人一定要选哦",onfocus:"你得认真思考哦",oncorrect:"不知道你爱不爱,反正你是选了"}).InputValidator({min:1,max:1,onerror:"难道你不爱国?你给我选!!!!"});
$("#shouji").formValidator({empty:true,onshow:"请输入你的手机号码,可以为空哦",onfocus:"你要是输入了,必须输入正确",oncorrect:"谢谢你的合作",onempty:"你真的不想留手机号码啊?"}).InputValidator({min:11,max:11,onerror:"手机号码必须是11位的,请确认"}).RegexValidator({regexp:"^[1][0-9]{10}$",onerror:"你输入的手机格式不正确"});
$("#lxdh").formValidator({empty:true,onshow:"请输入你的联系电话,可以为空哦",onfocus:"你要是输入了,必须输入正确,格式例如:0577-88069620",oncorrect:"谢谢你的合作",onempty:"你真的不想留联系电话了吗?"}).RegexValidator({regexp:"^[[0-9]{3}-|\[0-9]{4}-]?(\[0-9]{8}|[0-9]{7})?$",onerror:"你输入的联系电话格式不正确"});
$("#ms").formValidator({onshow:"请输入你的描述",onfocus:"描述至少要输入10个汉字或20个字符",oncorrect:"恭喜你,你输对了"}).InputValidator({min:20,onerror:"你输入的描述长度不正确,请确认"});
});
</script>


6、特别说明

如果你在使用过程中碰到什么问题请给我留言,发现bug请不要自行修改,也请留言,达到完善插件的目的,真正服务每个程序开发人员
.
请保留插件的版权申明,谢谢
引用地址:http://www.cnblogs.com/wzmaodong/archive/2008/02/04/1034901.html

3、jQuery pageValidator插件 API帮助文档

目前支持4种大的校验方式,分别是:InputValidator(针对input、textarea、select控件的字符长度、值范围、选择个数的控制)、CompareValidator(提供2个对象的比较,目前可以比较字符串和数值型)、AjaxValidator(通过ajax到服务器上做数据校验)、RegexValidator(提供可扩展的正则表达式库) 、FunctionValidator (提供可扩展函数库来做校验)

每种格式支持的控件类型如下:

input textarea select
校验方式 text radio checkbox file password textarea select-one
InputValidator √ √ √ √ √ √ √
CompareValidator √ √ √ √
AjaxValidator √ √ √ √ √
RegexValidator √ √ √ √
FunctionValidator √ √ √ √ √ √ √
如果你用了不支持的校验功能,插件将忽略这个校验功能。

插件目前提示错误,有两种模式:showword和showalert,即文字提示和窗口提示,下面的4大验证方式,针对showalert这种方式不是都必须的,有些配置是没有作用的
下面分别罗列全局初始化和5种校验方式公开的属性
formValidator: 用来做初始化的类型,必须先执行。("√"为showalert可用参数)
属性 属性名称 默认值 showalert 详细解释
validatorGroup 校验组 "1" √ 一个页面的控件可以分成多个组,分开校验
empty 是否可以为空 false √
automodify 输入错误离开焦点的时候,自动修复错误 false √ 先给出提示然后,自动修复,目前只支持text、file、textarea三种类型
onempty 空时候的提示 "输入内容为空" 可以为空,为空时候的提示
onshow 显示时候的提示 "请输入内容"
onfocus 获得焦点的提示 "请输入内容"
oncorrect 输入正确后的提示 "输入正确" 当你焦点离开控件的时候,如果输入正确将出现该提示
onvalid 校验通过后的回调函数 null √ 参数1:对象本身
参数2:值
校验通过后,你还希望执行一些操作,你可以通过这个属性来执行。
返回值的意义:
true/false 校验成功/失败
字符串 校验失败,返回值当作自定义错误
无 处理过程
onfocusevent 获得焦点后要追加的回调函数 null √ 参数1:对象本身
onblurevent 失去焦点后要追加的回调函数 null √ 参数1:对象本身
tipid 显示错误的容器ID 表单ID+"Tip"
defaultvalue 默认值 null √ 所有input和select表单。如果你不设置就保持原值,一旦设置就设为默认值。
InputValidator:
属性 属性名称 默认值 详细解释
type 比较类型 "size" (对select无效)"size":表示比较长度 "value":比较值。
min 最小长度/值 0 (对select无效)
max 最大长度/值 99999999999999 (对select无效)
onerror 发生错误的提示 "输入错误"
defaultvalue 默认值 null 能满足预设默认值的需求
CompareValidator:
属性 属性名称 默认值 详细解释
desID 要比较控件的ID "" 要跟源目标进行比较的目标ID
operateor 比较符号 "=" 一共有如下几种类型:=、!=、>、>=、<、<=
datatype 数据类型 "string" 目前只支持2种:"string"、"number"
onerror 发生错误的提示 "输入错误"
RegexValidator:
属性 属性名称 默认值 详细解释
regexp 正则表达式 "" 采用的是显式构造函数new RegExp("pattern"[,"flags"]); 由于Javascript 中'\' 被用作转义字符,所以在使用显示构造函数构造实例对象的时候,需要使用'\\' 代替'\'
param 附加参数 "i" g:代表可以进行全局匹配。
i:代表不区分大小写匹配。
m:代表可以进行多行匹配。
可以任意组合,当然也可以不加参数
datatype 数据类型 "string" "string":自己写的表达式,"enum":枚举名。具体请见demo3.htm,你可以自己修改附加pageValidatorRegex.js里的枚举项目名和表达式。
onerror: 发生错误的提示 "输入错误"
AjaxValidator: 几乎所有的属性跟$.ajax()的属性一样,请参考$.ajax()函数的帮助
属性 属性名称 默认值 详细解释
type 请求的类型 "GET" "POST" 或 "GET"
url 发送到的URL地址 ""
datatype 返回的数据类型 "html" xml、html、script、json
data 数据 ""
async 是否以异步的方式发送 true
success 当请求成功时调用的函数 null
processdata 自动处理返回的数据为字符串 true 在默认的情况下,如果data选项传进的数据是一个对象而不是字符串,将会自动地被处理和转换成一个查询字符串
complete 当请求完成时调用的函数 null
beforesend 当请求前时调用的函数 null
buttons 你点提交的按钮(组)jQuery对象 null 当你触发了ajax校验,buttons里对应的按钮(组)就会灰掉,一直等待服务器返回数据为止
error 当请求失败时调用的函数 "请求失败" 你可以自己定义这个错误,在error里自动打出
FunctionValidator
属性 属性名称 默认值 返回值的解释
fun 外部函数名 默认当作处理过程
true/false 校验成功/失败
字符串 校验失败,返回值当作自定义错误
无 处理过程
公共函数: 主要是设置全局参数和判断是否通过校验
函数名 函数说明
$.formValidator.initConfig 参数:配置类型
属性 默认值 说明
validatorGroup "1" 你要针对哪个组进行配置
alertMessage false 是否弹出窗口
onSuccess null 该组校验通过后的回调函数,返回false,阻止表单的提交
submitOnce false 校验通过后,是否灰掉所有的提交按钮
onError null 该组校验失败后的回调函数, 有两个参数
第一个 一个校验没有通过的错误信息
第二个 一个校验没有通过的元素对象
$.formValidator.PageIsValid 一个参数: 不是配置类型
validatorGroup "1" 你要针对哪个组进行验证
$.formValidator.IsOneValid 一个参数: 当时设置验证的表单元素ID。
返回是否校验成功的信息。
$.formValidator.SetFailState function("tipid","显示的信息")
在showword模式下,如果你的额外校验没有通过,你可以通过它来设置成失败信息和状态
$.formValidator.GetLength function("表单元素id")
判断表单元素的选择长度(个数)
checkbox或radiobutton表示选择的个数。
select表示选择的selectedIndex值。
其它的表示字符长度。



4、下载API帮助、源码、示例

下载
2.9版本发现一个逻辑bug,正在修复当中,现停止下载

http://www.cnblogs.com/Files/wzmaodong/formValidator2.9.rar
http://www.cnblogs.com/Files/wzmaodong/formValidator2.4.rar



5、示例代码

<script type="text/javascript">
$(document).ready(function(){
$.formValidator.initConfig({onError:function(){alert("校验没有通过,具体错误请看错误提示")}});
$("#test1").formValidator({onshow:"请输入用户名",onfocus:"用户名至少6个字符,最多10个字符",oncorrect:"恭喜你,你输对了"}).InputValidator({min:6,max:10,onerror:"你输入的用户名非法,请确认"});

$("#test2").formValidator({onshow:"请选择你的兴趣爱好(至少选择3个,最多选择5个)",onfocus:"你至少选择3个,最多选择5个",oncorrect:"恭喜你,你选对了"}).InputValidator({min:3,max:5,onerror:"你选的个数不对(至少选择3个,最多选择5个)"});

$("#test3").formValidator({onshow:"请选择你的兴趣爱好(至少选一个)",onfocus:"你至少选择1个",oncorrect:"恭喜你,你选对了"}).InputValidator({min:1,onerror:"你选的个数不对"});

$("#xueli").formValidator({onshow:"请选择你的学历",onfocus:"学历必须选择",oncorrect:"谢谢你的配合"}).SelectValidator({onerror: "你是不是忘记选择学历了!"});

$("#password1").formValidator({onshow:"请输入密码",onfocus:"两次密码必须一致哦",oncorrect:"密码一致"}).InputValidator({min:1,onerror:"密码不能为空,请确认"}).CompareValidator({desID:"password2",operateor:"=",onerror:"2次密码不一致,请确认"});

$("#nl").formValidator({onshow:"请输入的年龄(1-99岁之间)",onfocus:"只能输入1-99之间的数字哦",oncorrect:"恭喜你,你输对了"}).InputValidator({min:1,max:99,type:"value",onerror:"年龄必须在1-99之间,请确认"});

$("#aiguo").formValidator({onshow:"爱国的人一定要选哦",onfocus:"你得认真思考哦",oncorrect:"不知道你爱不爱,反正你是选了"}).InputValidator({min:1,max:1,onerror:"难道你不爱国?你给我选!!!!"});

$("#shouji").formValidator({empty:true,onshow:"请输入你的手机号码,可以为空哦",onfocus:"你要是输入了,必须输入正确",oncorrect:"谢谢你的合作",onempty:"你真的不想留手机号码啊?"}).InputValidator({min:11,max:11,onerror:"手机号码必须是11位的,请确认"}).RegexValidator({regexp:"^[1][0-9]{10}$",onerror:"你输入的手机格式不正确"});

$("#lxdh").formValidator({empty:true,onshow:"请输入你的联系电话,可以为空哦",onfocus:"你要是输入了,必须输入正确,格式例如:0577-88069620",oncorrect:"谢谢你的合作",onempty:"你真的不想留联系电话了吗?"}).RegexValidator({regexp:"^[[0-9]{3}-|\[0-9]{4}-]?(\[0-9]{8}|[0-9]{7})?$",onerror:"你输入的联系电话格式不正确"});

$("#ms").formValidator({onshow:"请输入你的描述",onfocus:"描述至少要输入10个汉字或20个字符",oncorrect:"恭喜你,你输对了"}).InputValidator({min:20,onerror:"你输入的描述长度不正确,请确认"});
});
</script>



6、特别说明

如果你在使用过程中碰到什么问题请给我留言,发现bug请不要自行修改,也请留言,达到完善插件的目的,真正服务每个程序开发人员
.
请保留插件的版权申明,谢谢

jQuery的bind函数

jQuery的bind函数

jQuery学习之bind

在mootools里面,如果要为某个DOM或者HTML标签等绑定一个操作用的是addEvents,移除一个事件的时候用的是removeEvents,在jQuery里面就相对比较简单,直接用bind函数和unbind函数就行了。

例如为一个button添加一个click。可以这样操作

<input type='button' id='myBtn'>

这是一个button,现在我们要为他添加一个事件

<script>
$('#myBtn').bind("click",function(){
alert('click');
});
</script>

这样,我们就为这个button绑定了一个click的事件。

bind函数可以有三个参数,当第二个参数不是一个函数,而是一个数据对象时,它将默认做为bind第三个参数(函数)的参数。例如:

<script>
function showAlert(events){
alert(events.data.foo);
}
$('#myBtn').bind('click',{foo:'click'},showAlert);
</script>

点击时,同样会显示:click

这些就是bind的一些基本用法,当然还有一些方法

比如在绑定方法的时候,用的是return false;可以让这个方法失效

<script>
$('#myBtn').bind('click',function(){
return false;
})
</script>

这样,刚才绑定的click又失效了,不过,这种方法往往用在submit提交的时候比较多。

还有一些方法可以取消默认行为和阻止事件起泡:preventDefault 和stopPropagation

例:

<script>
$('#myBtn').bind('click',function(event){
event.preventDefault();//取消默认的click行为
});
$('#myBtn').bind('click',function(event){
event.stopPropagation();//阻止click事件起泡
});

</script>
推荐一个Jquery插件:autoComplete

推荐一个Jquery插件:autoComplete

我就不翻译了……

这些东西也不复杂。

Copy网站开始……黑黑

Dependencies

Known issues:

  • When completing multiple values, only the last value can be edited with the autocomplete help
  • mustMatch option is broken (mostly fixed in latest revision)
  • default browser autocomplete displays a long list of values scrollable, that isn’t supported yet

Recent changes

Documentation

Autocompletition of input elements is a very helpful tool to guide users in entering the right value. That value can come from a (big) list of possible values or it may consist of values the user has entered before. This plugin makes it easy for a developer to setup autocomplete for text inputs and textareas.

Setup
First step in setting up autocomplete is to decide what kind of data is provided. To autocomplete a few dozen possible values, it is a good idea to provide local data. The data is loaded only once and then cached, providing a very responsive interface.
If the data can consist of hundreds, thousands or even millions of rows, the searching and filtering must be done where performance won’t suffer, in most cases a relational database (eg. MySQL). The plugin will request the rows for the entered value, displaying only a subset of all possible values.
For local autocomplete, just pass the data as an array to the autocomplete plugin. For remote autocomplete, specify an URL pointing to the resource providing the data. The plugin then requests data with a “q” parameter containing the current search value.

API

  • autocomplete( String|Array urlOrData, Map options ) returns jQuery
    Provide autocomplete for text-inputs or textareas.

    Depends on dimensions plugin’s offset method for correct positioning of the select box and bgiframe plugin
    to fix IE’s problem with selects.

    Options

    • inputClass (String): This class will be added to the input box. Default: “ac_input”
    • resultsClass (String): The class for the UL that will contain the result items (result items are LI elements). Default: “ac_results”
    • loadingClass (String): The class for the input box while results are being fetched from the server. Default: “ac_loading”
    • minChars (Number): The minimum number of characters a user has to type before the autocompleter activates. Default: 1
    • delay (Number): The delay in milliseconds the autocompleter waits after a keystroke to activate itself. Default: 400 for remote, 10 for local
    • cacheLength (Number): The number of backend query results to store in cache. If set to 1 (the current result), no caching will happen. Do not set below 1. Default: 10
    • matchSubset (Boolean): Whether or not the autocompleter can use a cache for more specific queries. This means that all matches of “foot” are a subset of all matches for “foo”. Usually this is true, and using this options decreases server load and increases performance. Only useful with cacheLength settings bigger then one, like 10. Default: true
    • matchCase (Boolean): Whether or not the comparison is case sensitive. Only important only if you use caching. Default: false
    • matchContains (Boolean): Whether or not the comparison looks inside (i.e. does “ba” match “foo bar”) the search results. Only important if you use caching. Don’t mix with autofill. Default: false
    • mustMatch (Booolean): If set to true, the autocompleter will only allow results that are presented by the backend. Note that illegal values result in an empty input box. Default: false
    • extraParams (Object): Extra parameters for the backend. If you were to specify { bar:4 }, the autocompleter would call my_autocomplete_backend.php?q=foo&bar=4 (assuming the input box contains “foo”). Default: {}
    • selectFirst (Boolean): If this is set to true, the first autocomplete value will be automatically selected on tab/return, even if it has not been handpicked by keyboard or mouse action. If there is a handpicked (highlighted) result, that result will take precedence. Default: true
    • formatItem (Function): Provides advanced markup for an item. For each row of results, this function will be called. The returned value will be displayed inside an LI element in the results list. Autocompleter will provide 3 parameters: the results row, the position of the row in the list of results (starting at 1), and the number of items in the list of results. Default: none, assumes that a single row contains a single value.
    • formatResult (Function): Similar to formatResult, but provides the formatting for the value to be put into the input field. Again three arguments: Data, position (starting with one) and total number of data. Default: none, assumes either plain data to use as result or uses the same value as provided by formatItem.
    • multiple (Boolean): Whether to allow more then one autocomplted-value to enter. Default: false
    • multipleSeparator (String): Seperator to put between values when using multiple option. Default: “, “
    • width (Number): Specify a custom width for the select box. Default: width of the input element
    • autoFill (Boolean): Fill the textinput while still selecting a value, replacing the value if more is type or something else is selected. Default: false
    • max (Number): Limit the number of items in the select box. Is also send as a “limit” parameter with a remote request. Default: 10

    Example:

    Autocomplete a text-input with remote data. For small to giant datasets.

    When the user starts typing, a request is send to the specified backend (”my_autocomplete_backend.php”),
    with a GET parameter named q that contains the current value of the input box and a paremeter “limit” with
    the value specified for the max option.

    A value of “foo” would result in this request url: my_autocomplete_backend.php?q=foo&limit=10

    The result must return with one value on each line. The result is presented in the order
    the backend sends it.

    $("#input_box").autocomplete("my_autocomplete_backend.php");

    HTML:

    <input id="input_box" />

    Example:

    Autcomplete a text-input with local data. For small datasets.

    $("#input_box").autocomplete(["Cologne", "Berlin", "Munich"]);

    HTML:

    <input id="input_box" />

    Example:

    Autcomplete a text-input with data received via AJAX. For small to medium sized datasets.

    $.getJSON("my_backend.php", function(data) {
      $("#input_box").autocomplete(data);
    });

    HTML:

    <input id="input_box" />

    Example:

    Autcomplete a textarea with local data (for small datasets). Once the user chooses one
    value, a separator is appended (by default a comma, see multipleSeparator option) and more values
    are autocompleted.

    $("#mytextarea").autocomplete(["Cologne", "Berlin", "Munich"], {
     multiple: true
    });

    HTML:

    <textarea id="mytextarea" />
  • result( Function handler ) returns jQuery
    Handle the result of a search event. Is executed when the user selects a value or a
    programmatic search event is triggered (see search()).

    You can add and remove (using unbind(”result”)) this event at any time.

    Example:

    Bind a handler to the result event to display the selected value in a #result element.
    The first argument is a generic event object, in this case with type “result”.
    The second argument refers to the selected data, which can be a plain string value or an array or object.
    The third argument is the formatted value that is inserted into the input field.

    jQuery('input#suggest').result(function(event, data, formatted) {
      jQuery("#result").html( !data ? "No match!" : "Selected: " + formatted);
    });
  • search( ) returns jQuery
    Trigger a search event. See result(Function) for binding to that event.

    A search event mimics the same behaviour as when the user selects a value from
    the list of autocomplete items. You can use it to execute anything that does something
    with the selected value, beyond simply putting the value into the input and submitting it.

    Example:

    Triggers a search event.

    jQuery('input#suggest').search();

jQuery一些插件的链接[转]

文件上传(File upload)JQuery_001

Ajax File Upload.
jQUploader.
Multiple File Upload plugin.
jQuery File Style.
Styling an input type file.
Progress Bar Plugin.

表单验证(Form Validation)

jQuery Validation.
Auto Help.
Simple jQuery form validation.
jQuery XAV - form validations.
jQuery AlphaNumeric.
Masked Input.
TypeWatch Plugin.
Text limiter for form fields.
Ajax Username Check with jQuery.

表单-选取框(Form - Select Box stuff)

jQuery Combobox.
jQuery controlled dependent (or Cascadign) Select List.
Multiple Selects.
Select box manipulation.
Select Combo Plugin.
jQuery - LinkedSelect
Auto-populate multiple select boxes.
Choose Plugin (Select Replacement).

表单基本、输入框、选择框等(Form Basics, Input Fields, Checkboxes etc.)

jQuery Form Plugin.
jQuery-Form.
jLook Nice Forms.
jNice.
Ping Plugin.
Toggle Form Text.
ToggleVal.
jQuery Field Plugin.
jQuery Form’n Field plugin.
jQuery Checkbox manipulation.
jTagging.
jQuery labelcheck.
Overlabel.
3 state radio buttons.
ShiftCheckbox jQuery Plugin.
Watermark Input.
jQuery Checkbox (checkboxes with imags).
jQuery SpinButton Control.
jQuery Ajax Form Builder.
jQuery Focus Fields.
jQuery Time Entry.

时间、日期和颜色选取(Time, Date and Color Picker)

jQuery UI Datepicker.
jQuery date picker plugin.
jQuery Time Picker.
Time Picker.
ClickPick.
TimePicker.
Farbtastic jQuery Color Picker Plugin.
Color Picker by intelliance.fr.

投票插件(Rating Plugins)

jQuery Star Rating Plugin.
jQuery Star Rater.
Content rater with asp.net, ajax and jQuery.
Half-Star Rating Plugin.

搜索插件(Search Plugins)

jQuery Suggest.
jQuery Autocomplete.
jQuery Autocomplete Mod.
jQuery Autocomplete by AjaxDaddy.
jQuery Autocomplete Plugin with HTML formatting.
jQuery Autocompleter.
AutoCompleter (Tutorial with PHP&MySQL).
quick Search jQuery Plugin.

编辑器(Inline Edit & Editors)JQuery_002

jTagEditor.
WYMeditor.
jQuery jFrame.
Jeditable - edit in place plugin for jQuery.
jQuery editable.
jQuery Disable Text Select Plugin.
Edit in Place with Ajax using jQuery.
jQuery Plugin - Another In-Place Editor.
TableEditor.
tEditable - in place table editing for jQuery.

多媒体、视频、Flash等(Audio, Video, Flash, SVG, etc)

jMedia - accessible multi-media embedding.
JBEdit - Ajax online Video Editor.
jQuery MP3 Plugin.
jQuery Media Plugin.
jQuery Flash Plugin.
Embed QuickTime.
SVG Integration.

图片(Photos/Images/Galleries)

ThickBox.
jQuery lightBox plugin.
jQuery Image Strip.
jQuery slideViewer.
jQuery jqGalScroll 2.0.
jQuery - jqGalViewII.
jQuery - jqGalViewIII.
jQuery Photo Slider.
jQuery Thumbs - easily create thumbnails.
jQuery jQIR Image Replacement.
jCarousel Lite.
jQPanView.
jCarousel.
Interface Imagebox.
Image Gallery using jQuery, Interface & Reflactions.
simple jQuery Gallery.
jQuery Gallery Module.
EO Gallery.
jQuery ScrollShow.
jQuery Cycle Plugin.
jQuery Flickr.
jQuery Lazy Load Images Plugin.
Zoomi - Zoomable Thumbnails.
jQuery Crop - crop any image on the fly.
Image Reflection.

Google地图(Google Map)

jQuery Plugin googlemaps.
jMaps jQuery Maps Framework.
jQmaps.
jQuery & Google Maps.
jQuery Maps Interface forr Google and Yahoo maps.
jQuery J Maps - by Tane Piper.

游戏(Games)

Tetris with jQuery.
jQuery Chess.
Mad Libs Word Game.
jQuery Puzzle.
jQuery Solar System (not a game but awesome jQuery Stuff).

表格等(Tables, Grids etc.)

UI/Tablesorter.JQuery_003
jQuery ingrid.
jQuery Grid Plugin.
Table Filter - awesome!.
TableEditor.
jQuery Tree Tables.
Expandable “Detail” Table Rows.
Sortable Table ColdFusion Costum Tag with jQuery UI.
jQuery Bubble.
TableSorter.
Scrollable HTML Table.
jQuery column Manager Plugin.
jQuery tableHover Plugin.
jQuery columnHover Plugin.
jQuery Grid.
TableSorter plugin for jQuery.
tEditable - in place table editing for jQuery.
jQuery charToTable Plugin.
jQuery Grid Column Sizing.
jQuery Grid Row Sizing.

统计图(Charts, Presentation etc.)

jQuery Wizard Plugin .
jQuery Chart Plugin.
Bar Chart.

边框、圆角、背景(Border, Corners, Background)

jQuery Corner.
jQuery Curvy Corner.
Nifty jQuery Corner.
Transparent Corners.
jQuery Corner Gallery.
Gradient Plugin.

文字和超链接(Text and Links)

jQuery Spoiler plugin.
Text Highlighting.
Disable Text Select Plugin.
jQuery Newsticker.
Auto line-height Plugin.
Textgrad - a text gradient plugin.
LinkLook - a link thumbnail preview.
pager jQuery Plugin.
shortKeys jQuery Plugin.
jQuery Biggerlink.
jQuery Ajax Link Checker.

鼠标提示(Tooltips)

jQuery Plugin - Tooltip.
jTip - The jQuery Tool Tip.
clueTip.
BetterTip.
Flash Tooltips using jQuery.
ToolTip.

菜单和导航(Menus, Navigations)

jQuery Tabs Plugin - awesome! . [demo nested tabs.]
another jQuery nested Tab Set example (based on jQuery Tabs Plugin).
jQuery idTabs.
jdMenu - Hierarchical Menu Plugin for jQuery.
jQuery SuckerFish Style.
jQuery Plugin Treeview.
treeView Basic.
FastFind Menu.
Sliding Menu.
Lava Lamp jQuery Menu.
jQuery iconDock.
jVariations Control Panel.
ContextMenu plugin.
clickMenu.
CSS Dock Menu.
jQuery Pop-up Menu Tutorial.
Sliding Menu.

http://stilbuero.de/jquery/tabs_3/

幻灯、翻转等(Accordions, Slide and Toggle stuff)

jQuery Plugin Accordion.
jQuery Accordion Plugin Horizontal Way.
haccordion - a simple horizontal accordion plugin for jQuery.
Horizontal Accordion by portalzine.de.
HoverAccordion.
Accordion Example from fmarcia.info.
jQuery Accordion Example.
jQuery Demo - Expandable Sidebar Menu.
Sliding Panels for jQuery.
jQuery ToggleElements.
Coda Slider.
jCarousel.
Accesible News Slider Plugin.
Showing and Hiding code Examples.
jQuery Easing Plugin.
jQuery Portlets.
AutoScroll.
Innerfade.

拖放插件(Drag and Drop)

UI/Draggables.
EasyDrag jQuery Plugin.
jQuery Portlets.
jqDnR - drag, drop resize.
Drag Demos.

XML XSL JSON Feeds

XSLT Plugin.
jQuery Ajax call and result XML parsing.
xmlObjectifier - Converts XML DOM to JSON.
jQuery XSL Transform.
jQuery Taconite - multiple Dom updates.
RSS/ATOM Feed Parser Plugin.
jQuery Google Feed Plugin.

浏览器(Browserstuff)

Wresize - IE Resize event Fix Plugin.
jQuery ifixpng.
jQuery pngFix.
Link Scrubber - removes the dotted line onfocus from links.
jQuery Perciformes - the entire suckerfish familly under one roof.
Background Iframe.
QinIE - for proper display of Q tags in IE.
jQuery Accessibility Plugin.
jQuery MouseWheel Plugin.

对话框、确认窗口(Alert, Prompt, Confirm Windows)

jQuery Impromptu.
jQuery Confirm Plugin.
jqModal.
SimpleModal.

CSS

jQuery Style Switcher.
JSS - Javascript StyleSheets.
jQuery Rule - creation/manipulation of CSS Rules.
jPrintArea.

DOM、AJAX和其它JQuery插件(DOM, Ajax and other jQuery plugins)

FlyDOM.
jQuery Dimenion Plugin.
jQuery Loggin.
Metadata - extract metadata from classes, attributes, elements.
Super-tiny Client-Side Include Javascript jQuery Plugin.
Undo Made Easy with Ajax.
JHeartbeat - periodically poll the server.
Lazy Load Plugin.
Live Query.
jQuery Timers.
jQuery Share it - display social bookmarking icons.
jQuery serverCookieJar.
jQuery autoSave.
jQuery Puffer.
jQuery iFrame Plugin.
Cookie Plugin for jQuery.
jQuery Spy - awesome plugin.
Effect Delay Trick.
jQuick - a quick tag creator for jQuery.
Metaobjects
.
elementReady.

JQuery学习第一天

JQuery,prototype,mootools是现在应用的比较多的JS框架了

其它的我就不谈了,现在正在用JQuery,正好做个笔记。

用JQuery官方的话来说,一般普通开发人员,如果仅仅是为了使用JQuery的话,那么,用的最多的应该是XPath,Css,只有这两个熟悉了,才能完整的使用JQuery,而XPath又是重中之重。

XPath的功能是让你可以在DOM里迅速定位到某一个确定的元素,在以前,我们不得不通过:getElementById,getElementsByName,等函数来得定位元素,而现在,$(),几乎可以完成常用的功能。

$('#test'),代表了以前的document.getElementById('test');

当然,这只是最简单的,复杂的就是在那些Xpath上了,例如
$("div > p") ,$("//div/p")等等
更详细的,可以参考:http://docs.jquery.com/DOM/Traversing/Selectors

用完了XPath后,就是一些常用的事件了,如click,mouseover,mouseout等这些都是可以后定义的也算是比较方便

对于页面元素,JQuery也简化了一些操作,比如取input框的值,取innerHTML,innerText等,不但取值方便,而且设定值的时候也非常方便。

今天的笔记就做到这样,只能算是稍稍理一下思路。慢慢再写