1.以屏幕可用宽和高的百分比来定义弹出框的宽和高
var trueWidth = $(top.window).width() * 0.9;
var trueHeight = $(top.window).height() * 0.9;
2.光标离开时验证是否数字
//js
function CheckIsNan(t){
var IsNanValue=$(t).val();
var strP=/^\d+$/;
if(!strP.test(IsNanValue)) { 
alert("请输入数字!"); 
$(t).focus();
return false; 
}
}
//html
<td><input name="number" onblur="CheckIsNan(this)"/></td>
3.失去焦点时给文本框默认值
//js
function cls(t) {
//如果当前值为默认值,则清空
if ($(t).val() == "输入首字母或名字检索") $(t).val("");
}
function res(t) {
//如果当前值为空,则重置为默认值
if ($(t).val() == "") $(t).val("输入首字母或名字检索");
}
//html
<input id="userName" value="输入首字母或名字检索" onfocus="cls(this)" onblur="res(this)" />
4.把输入为数字的时间转换为年-月-日形式
function changeTime(t) {
var time = $(t).val();
var strP = /^\d+$/;
if (!strP.test(time)) {
alert("请输入八位时间数字!");
twice += 1;
if (twice < 3) {
$(t).focus();//超过两次操作有误时,就不回光标
}
else {
twice = 1
}
return false;
}
if (time.length == 8) {
var year = time.substring(0, 4);
var month = time.substring(4, 6);
var day = time.substring(6, 8);
$(t).val(year + "-" + month + "-" + day);
} else {
alert("请输入八位时间数字!");
}
}
5.在table中全部选中行
 function checkAll(t) {
            var isBool = t.checked;//t一般是写this
            var a = $(t).parent().parent().children().children().children().children("td").children("input").each(function () {
                //js 的动态添加属性
                this.checked = isBool;
            });
6.在table中反选操作
function InvertSelection(t) {
            var isBool = t.checked;
            if (isBool) {
                 //选择反选时,全选按钮应该去掉打勾  
             $(t).parent().parent().parent().parent().parent().children("legend").children("input[name=‘listcheckbox‘]").each(function () {
                    //js 的动态添加属性
                    this.checked = false;
                });
                $(t).parent().parent().parent().parent().parent().children().children().children().children("td").children("input").each(function () {
                    //js 的动态添加属性
                    if (this.checked == true) {
                        this.checked = false;
                    }
                    else {
                        this.checked = true;
                    }
                });
            }
            else {
//               
                    $(t).parent().parent().parent().parent().parent().children().children().children().children("td").children("input").each(function () {
                        //js 的动态添加属性
                        if (this.checked == true) {
                            this.checked = false;
                        }
                        else {
                            this.checked = true;
                        }
                    });
                
            }
            
            var b = $(t).parent().parent().parent().parent().parent().children("legend");
         }
7.当勾选复选框时跳转到指定页面-----------------
  function checkMore(t) {
            var isBool = t.checked;
            if (isBool) {
                location.href = "../Admin/AfterStorage.aspx";
            }
            else {
                location.href = "../Admin/AuditedSupply.aspx";
            }
         }
8.前台传值的时候先编码 
$.post("/Admin/SuppliesOrder/Actions/FuzzyCheckConsumable.ashx?keyword=" + escape(request.term)//escape就是用来解码
//后台接收传值时再解码
string  keyword = System.Web.HttpContext.Current.Server.UrlDecode(keyword);
9.清除查询条件
       function ClearQuery() {
          $(‘#tbsearch‘).find("input").val("");
           }
原文地址:http://www.cnblogs.com/115FXC/p/3864635.html