公用js

//Textarea长度限定 
$("textarea[maxlength]").live('keypress focusout', function () { 
var area = $(this); 
var max = parseInt(area.attr("maxlength"), 10); 
if (max > 0) { 
if (area.val().length > max) { 
area.val(area.val().substr(0, max)); 


}); 

//输入框的文字占位

$('input.search,textarea.search').each(function(){

var self = $(this);

var data = self.val();

self.data('value',data).focus(function(){

if( self.val() == self.data('value') ){

self.val('');

}

}).blur(function(){

if( self.val() == '' ){

self.val(self.data('value'));

}

});

});

//提交后提示多少秒之后回到某个页面

var countTime = 5;

var setT = function(){

    $('#num').empty().text(countTime);

    countTime--;

    if(countTime>0){

        setTimeout(function(){setT();},800);

    } else {

        window.history.back(-1);

    }

};

//Cookies

function setCookie(c,d,e){if(e){var b=new Date();b.setTime(b.getTime()+(e*24*60*60*1000));var a="; expires="+b.toGMTString()}else{var a=""}document.cookie=c+"="+d+a+"; path=/"}function getCookie(b){var e=b+"=";var a=document.cookie.split(";");for(var d=0;d<a.length;d++){var f=a[d];while(f.charAt(0)==" "){f=f.substring(1,f.length)}if(f.indexOf(e)==0){return f.substring(e.length,f.length)}}return null}function deleteCookie(a){setCookie(a,"",-1)};

<input class="button" type="button" value="插入Cookie" onclick="setCookie('aTestCookie','Test Cookie',100)" /> 

<input class="button" type="button" value="删除Cookie" onclick="deleteCookie('aTestCookie')" /><br /> 

<input class="button" type="button" value="读取Cookie" onclick="alert(getCookie('aTestCookie'))" />

插入时用 setCookie() ,三个参数分别为Cookie的key、value和保存的天数

读取时用getCookie(),删除时用deleteCookie(),两个的参数都为Cookie的key

//Check Browser Version

function ieVersion(){

if ($.browser.msie) {

var ieVersion = 8;

ieVersion = 8;

if ($.browser.version < 8) {

ieVersion = 7;

if ($.browser.version < 7) {

ieVersion = 6;

}

}

} else {

ieVersion = 100;

}

return ieVersion;

}

<input class="button" type="button" value="点击查看" onclick="alert('你正在使用'+(ieVersion<=8?('IE'+ieVersion()):'Firefox或其他非IE浏览器'))" />

调用 ieVersion(); 可以直接返回当前IE浏览器版本,如果是非IE浏览器则返回100

14.js代码: 

try { 

p_selYear = parseInt($("#yyyy").text()); 

p_selMonth = parseInt($("#mm").text()); 

} catch (err) { 

var d = new Date(); 

p_selYear = d.getFullYear(); 

p_selMonth = d.getMonth(); 

d = null; 

1.JSON.parse() 

<% if(Request.IsAuthenticated) { %> 

<% if (Model.IsUserRegistered(Context.User.Identity.Name)) { %> //注意前面的Context 

$table.jqGrid('editRow', curNewRow); 

$(tableName).jqGrid('setSelection', curNewRow); 

overflow:auto; overflow-y:hidden; 

.links ul li a{ opacity:0.6;} 

.links ul li a img{ border:1px solid #09c; filter:alpha(opacity=60);} 

.links ul li a:hover{ opacity:1;} 

.links ul li a:hover img{ border-color:#BF523B; filter:alpha(opacity=100);} 

$('#tabDiv').tabs('select', 0); 

var params = $.extend({ pduName: pduName }, getParams()); 

JavaScriptSerializer json = new JavaScriptSerializer();return json.Serialize(auth);//返回string类型的数据 

jqgrid默认选中第一行 

var ids = $("#list").getDataIDs(); 

if (ids.length > 0) { 

$("#list").jqGrid('setSelection', "" + ids[0]); //将会触发onSelectRow事件 

jqgrid获取选中行对象 

var sr = $("#list").getGridParam('selrow'); 

var pbiName = $("#list").getRowData(sr).pbiName;

2. 

onSelectRow: function (id) { 

if (id == curNewRow) { 

curSelRow = id; 

return;//新增加行的选中事件 

var $table = $(tableName); 

if (curNewRow != -1) { 

if (!confirm("当前存在新增而未提交的行?确认放弃提交吗?")) { 

return; 

} else { 

cancelNewRow(); 

if (curEditRow != -1) { 

if (!confirm("存在编辑未提交的行?确认放弃提交吗?")) { 

return; 

curEditRow = -1; 

curNewRow = -1; 

curSelRow = id; 

disableRowEdit(); //禁止提交 

orgAuthTree.setSubChecked("0", 0); //重置所有选择 

initRowData(); //初始化行数据值,得到选择行数据 

for (var index in rowData) { 

if (index.toString() == 'undefined') { 

continue; 

str = Trim($table.getCell(curSelRow, index)); 

//str = $(tableName).find("#" + curSelRow + "_" + index).val(); 

rowData[index] = Trim(str); 

CheckOrgAuthTree(rowData.UserID, rowData.RoleID); //查询并选中当前行所决定的部门

}

//offset:离今天的偏移量,正数则向后偏,负则向前偏 
function initDatePicker(pId, offset) { 
if (offset == 0) { 
$("#" + pId).datepicker('setDate', new Date()); 
return; 

else { 
$("#" + pId).datepicker('setDate', offset); 




/*iframe高度自适应*/ 
function resizeHeight(obj) { 
var cwin = obj; 
var defaultHeight = 550; 
if (document.getElementById) { 
if (cwin && !window.opera) { 
if (cwin.contentDocument && cwin.contentDocument.body.offsetHeight) { 
var h = cwin.contentDocument.body.offsetHeight; 
cwin.height = (h < defaultHeight)?defaultHeight:h; 

else if (cwin.Document && cwin.Document.body.scrollHeight) { 
var h = cwin.Document.body.scrollHeight; 
cwin.height = (h < defaultHeight) ? defaultHeight : h; 



//javascript判断字符长度最好的方法

function getStringlength(str) { 
return str.replace(/[^\x00-\xff]/g, "**").length; 
}


//点击收缩
$('dt').live('click',function () {
var self = $(this);
self.toggleClass('closed');
var rel = self.nextAll("dd");
rel.slideToggle(300, function () {
//加减号变换
//self.toggleClass('closed');

});
});


//点击iframe页面不刷新 
<div id="divLeft"> 
<div id="divLeftInner"> 
<dl id="dlSideNav"> 
<dt>资产管理</dt> 
<dd rel="/MyDutyField/MyDutyField">子责任田资产管理</dd> 
<dd rel="/MyDutyField/MyVersionAreaField">版本领域资产管理</dd> 
<dt>版本管理</dt> 
<dd>版本配置</dd> 
<dd>版本质量要求</dd> 
</dl> 
</div> 
</div> 
<div id="divRight"> 
<div id="divRightInner"> 
<iframe id="iFrame1" name="iFrame1" width="100%" onload="this.height=iFrame1.document.body.scrollHeight" frameborder="0"> 
</iframe> 
</div> 
</div> 


$('#dlSideNav').delegate('dt', 'click', function () { 
$(this).toggleClass('hide'); 
}); 
$('#dlSideNav').delegate('dd', 'click', function () { 
var rel = $(this).attr('rel'); 
if (rel != null && rel.length > 1) { 
$('#iFrame1').attr('src', rel); 
} else { 
alert('页面不存在'); 

});

 

//js验证输入的为整数;

function CheckSort() {

var regu = /^[-]{0,1}[0-9]{1,}$/;
if (regu.test($("#Entity_Sort").val())) {
$("#Sort_span").show();
}
else {
$("#Sort_span").hide();
}
}




工具:
页面效果图 Balsamiq.Mockups.v1.6.62
数据库对比工具 godswsqlcompare_setup.exe

posted on 2011-01-29 22:09  cw_volcano  阅读(477)  评论(0编辑  收藏  举报