1》
前进:window.history.go(1) / window.history.forward();
后退:window.history.go(-1) / window.history.back();
后退+刷新:window.history.go(-1) / window.location.reload();
2》为某一个事件附加其他的事件
var element=document.getElement("para");
if(element.addEventListener){
element.addEventListener("focus",函数,false);
}else{
element.attachEvent("onfocus",函数);
}
3》获取地址栏中上一页的地址
Request.UrlReferrer.ToString(); asp.net
top.window.location.href JS
4》截取字符串
subString(开始索引,结束索引); JS asp.net
substr(开始索引,长度); JS
5》获取JS中下拉列表中的文本值
document.getElementsByName("select").options[document.getElementsByName("select").options.selectedIndex].text;
6》判断界面是否加载完毕
document.onreadystateChange=statechange;
function statechange(){
if(document.readystate="complete"){`````}
}
7》DataTable转换成List泛型集合
foreach(DataRow dr in dt.rows){
Model.User user=new Model.User();
user.userid=dr["userid"]=DBNull.value?(long)0:Convert.toInt16(dr["userid"]);
list.add(user);
}
8》 window.open的使用
function Change() {
window.open("help.html", "Help", "height=770,width=1000,top=0,left=225,tollbar=yes,menubar=yes,scrollbars=1,resizable=no,location=no,status=no");
}
9>绑定判断
public string returnStr(string str)
if(str=="1")
{
return "X路径";
}
else
{
return "Y路径";
}
在repeater中绑定的时候用一个label显示,绑定时路径src='<%# returnStr(label.text)%>'
10. HyperLink的使用[传递参数是绑定值]
<HyperLink ID="lnk" runat="server" NavigateUrl='<%#"~/Production.aspx?bn=" +DataBinder.Eval(Container.DataItem,"BillNum")%'>
11.JS获取服务器端的值
var date=document.all.<%=txtDate.ClientID%>.value;
12.文本框数字验证
onKeypress="return (/[\d.]/.test(String.fromCharCode(event.keyCode)))";
οnkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')";
13.QQ客服在线
<a href="tencent://message/?uin=372006497&Site=www.cnclcy&Menu=yes">372006497</a>
14.asp.net的md5加密
string password = FormsAuthentication.HashPasswordForStoringInConfigFile(Request.Form["Pwd"], "md5").ToLower();
15. 设置行索引
<asp:Lable ID="lbtnUpdate" runat="server" value='<%# Container.DataItemIndex%>' />
16. 在前台设置格式[小数点后面保留两位数]
<%# Convert.ToDecimal(Eval("Sales","{0:F2}").ToString()) < 0 ? "<font class='co2'>" + Eval("Sales") + "</font>" : Eval("Sales")%>
17. 小数点后保留两位在后台设置如下:
decimal pd = (Convert.ToDecimal(period)) * 100);
perd = string.Format("{0:f2}", pd);
18. JS获取行索引
window.event.srcElement.parentElement.parentElement.rowIndex;