1.定位div在网页中间
<div id="form" style="
position:absolute;
width:800px;
height:600px;
margin-left:50%;
left:-400px;
"></div>
<script type="text/javascript">
document.getElementById("form").style.top = document.documentElement.clientHeight / 2 - 600 / 2;
</script>
2.利用cookie长期保存用户ID
取cookie:
HttpCookie cookie = Request.Cookies["LoginID"];
设置cookie:
if (cookie == null || cookie["userid"] == null || cookie["userid"].ToString() != userid)
{
cookie = new HttpCookie("LoginID");
cookie["userid"] = userid;
cookie.Expires = DateTime.Now.AddYears(1);
Response.Cookies.Add(cookie);
}
3.后台获取前台的数据
object strID = Request.Params["id"];
string treeID = Request.QueryString["TreeID"];
string strData = Request.Form.ToString();
4.后台返回前台数据
Response.Write("{success:true}");
Response.Write(ExtTree.Current.CreateExtTreeJSON(treeID, cookie["userid"].ToString()));
Response.End();
5.网页放大缩小事件
var resizeTimer = null;
function doResize() {
//alert("width=" + document.documentElement.clientWidth + " Height=" + document.documentElement.clientHeight);
tabs.setHeight(document.documentElement.clientHeight-80-5);
}
window.onresize = function () {
if (resizeTimer) clearTimeout(resizeTimer);
resizeTimer = setTimeout("doResize()", 0);
}
6.点击button 弹出div层
<button id="button1" class="btn" onmouseout = "hidePopup();" onmouseover = "showPopup(220,300);"
<script type ="text/javascript">
// function showwin() {
// window.open("ButtonView.aspx", "", "height=400,width=200", "toolbar = no");
// }
var baseText = null;
function showPopup(w, h) {
var popUp = document.getElementById("popupcontent");
popUp.style.top = "50px";
popUp.style.left = document.documentElement.clientWidth / 2-220;
popUp.style.width = w + "px";
popUp.style.height = h + "px";
// if (baseText == null)
// baseText = popUp.innerHTML;
// popUp.innerHTML = baseText + "<div id=\"statusbar\"><input type=\"button\" value=\"关闭\" onClick=\"hidePopup();\"></div>";
// var sbar = document.getElementById("statusbar");
// sbar.style.marginTop = (parseInt(h) - 300) + "px";
popUp.style.visibility = "visible";
}
function hidePopup() {
var popUp = document.getElementById("popupcontent");
popUp.style.visibility = "hidden";
}
</script>
<div id="popupcontent"></div>
7.前台接受参数
var query = location.search.substring(1).split('&');
var id = query[0];
var text = (query[1]);
8.javascript 实现在线时间显示
function nowTime(){
/*
* ev:显示时间的元素
* type:时间显示模式.若传入12则为12小时制,不传入则为24小时制
*/
//年月日时分秒
var Y,M,D,W,H,I,S;
//月日时分秒为单位时前面补零
function fillZero(v){
if(v<10){v='0'+v;}
return v;
}
(function(){
var d=new Date();
var Week=['星期天','星期一','星期二','星期三','星期四','星期五','星期六'];
Y=d.getFullYear();
M=fillZero(d.getMonth()+1);
D=fillZero(d.getDate());
W=Week[d.getDay()];
H=fillZero(d.getHours());
I=fillZero(d.getMinutes());
S=fillZero(d.getSeconds());
// //12小时制显示模式
// if(type && type==12){
// //若要显示更多时间类型诸如中午凌晨可在下面添加判断
// if(H<=12){
// H='上午 '+H;
// }else if(H>12 && H<24){
// H-=12;
// H='下午 '+fillZero(H);
// }else if(H==24){
// H='下午 00';
// }
// }
document.getElementById("time").innerHTML='现在时间:'+Y+'年'+M+'月'+D+'日 '+' '+W+' '+H+':'+I+':'+S +' ';
//每秒更新时间
setTimeout(arguments.callee,1000);
})()
}
9. 判断各种浏览器
function IsWhichBrowser() {
var Sys = {};
var ua = navigator.userAgent.toLowerCase();
window.ActiveXObject ? Sys.ie = ua.match(/msie ([\d.]+)/)[1] :
document.getBoxObjectFor ? Sys.firefox = ua.match(/firefox\/([\d.]+)/)[1] :
window.MessageEvent && !document.getBoxObjectFor ? Sys.chrome = ua.match(/chrome\/([\d.]+)/)[1] :
window.opera ? Sys.opera = ua.match(/opera.([\d.]+)/)[1] :
window.openDatabase ? Sys.safari = ua.match(/version\/([\d.]+)/)[1] : 0;
return Sys;
}
// if (Sys.ie) alert('IE: ' + Sys.ie);
// if (Sys.firefox) alert('Firefox: ' + Sys.firefox);
// if (Sys.chrome) alert('Chrome: ' + Sys.chrome);
// if (Sys.opera) alert('Opera: ' + Sys.opera);
// if (Sys.safari) alert('Safari: ' + Sys.safari);
10. gridview 合并单元格
/// <summary>
/// 合并GridView中某列相同信息的行(单元格)
/// </summary>
/// <param name="GridView1">GridView</param>
/// <param name="cellNum">第几列</param>
public static void GroupRows(GridView GridView1, int cellNum)
{
int i = 0, rowSpanNum = 1;
while (i < GridView1.Rows.Count - 1)
{
GridViewRow gvr = GridView1.Rows[i];
for (++i; i < GridView1.Rows.Count; i++)
{
GridViewRow gvrNext = GridView1.Rows[i];
if (gvr.Cells[cellNum].Text == gvrNext.Cells[cellNum].Text)
{
gvrNext.Cells[cellNum].Visible = false;
rowSpanNum++;
}
else
{
gvr.Cells[cellNum].RowSpan = rowSpanNum;
rowSpanNum = 1;
break;
}
if (i == GridView1.Rows.Count - 1)
{
gvr.Cells[cellNum].RowSpan = rowSpanNum;
}
}
}
}
11. 预算sql
select
subject.subjectCode,
sum(DetailBudget.total) as total,
sum(case substring(projectCode,4,2) when 'A0' then DetailBudget.total else 0 end) as a0,
sum(case substring(projectCode,4,2) when 'A1' then DetailBudget.total else 0 end) as a1,
sum(case substring(projectCode,4,2) when 'A2' then DetailBudget.total else 0 end) as a2,
sum(case substring(projectCode,4,2) when 'B1' then DetailBudget.total else 0 end) as B1,
sum(case substring(projectCode,4,2) when 'B2' then DetailBudget.total else 0 end) as B2,
sum(case substring(projectCode,4,2) when 'B3' then DetailBudget.total else 0 end) as B3,
sum(case substring(projectCode,4,2) when 'B4' then DetailBudget.total else 0 end) as B4,
sum(case substring(projectCode,4,2) when 'B5' then DetailBudget.total else 0 end) as B5
from subject
left join DetailBudget on subject.subjectCode = DetailBudget.subjectCode
group by subject.subjectCode
order by subject.subjectCode
select
subject.subjectname,
subject.subjectCode,
sum(DetailBudget.total) as total
into #temp1
from subject
left join DetailBudget on subject.subjectCode = DetailBudget.subjectCode
where len(subject.subjectCode) = 3
group by subject.subjectCode,subject.subjectname
order by subject.subjectCode
select
subject.subjectCode,
sum(expenses.money) as totalmoney,
sum(case when month = '1' and year ='2012' then expenses.money else 0 end) as currentMonthMoney
into #temp2
from subject
left join expenses on subject.subjectCode = expenses.subjectCode
where len(subject.subjectCode) = 3
group by subject.subjectCode
order by subject.subjectCode
select
m.subjectname,
m.subjectCode,
m.total,
n.totalmoney,
n.currentMonthMoney,
case when m.total = 0 then 0 else cast(n.totalmoney/m.total as decimal(18,2)) end rate
from
(select * , px = row_number()over(order by getdate()) from #temp1) m
full join
(select * , px = row_number()over(order by getdate()) from #temp2) n
on m.px = n.px
drop table #temp1
drop table #temp2