(一).確認刪除用法:
? 1. BtnDel.Attributes.Add(“onclick”,”return confirm(‘”+”確認刪除?”+”‘)”);
? 2. linktempDelete.Attributes[“onclick”]=”javascript:return? confirm(‘”+”確認刪除?”+”‘);”;
? 3. private void grdProject_ItemDataBound(object sender, DataGridItemEventArgs e)
? 4.
? {
?if ((e.Item.ItemType == ListItemType.Item) | (e.Item.ItemType == ListItemType.AlternatingItem))
?{
??// ?除按怙上的提示部分
??e.Item.Cells[10].Attributes.Add(“onclick”, “return confirm(‘確定刪除嗎?’);”);
?}??
? }
? 5.
??? <script language=”JavaScript” type=”text/JavaScript”>
?function delete_y(e)
??????? {
??? if(event.srcElement.outerText == “刪除”)
??????? event.returnValue=confirm(“確定刪除?”);
?}
?document.onclick=delete_y;
??? </script>
(二).跨語言字符串替換
??? System.Text.RegularExpressions.Regex.Replace(str1,@”<{1}[^<>]*>{1}”,””).Replace(”?“,””).Replace(“\”,”\\”).Replace(“-“,”-“).Replace(“&”,”&”).Replace(“<“,”<“).Replace(“>”,”>”).Replace(“br”,”\n”);
(三).關閉窗體
?? 1.
????? this.btnClose.Attributes.Add(“onclick”,? “window.close();return false;”);
?? 2.關閉本窗體間跳轉到另一個頁面
????? this.HyperLink1.NavigateUrl = “javascript:onclick=window.opener.location.assign
???????? (‘” + “index.aspx”+ “?&Func=Edit&AutoID=” + intAutoid + ‘);window.close();”;
?? 3.關閉父窗體:
????? <INPUT type=”reset” value='<%=this._Cancel%>’ onclick=”window.parent.close()”? Class=”Button”>
(四).Web MessageBox
?? 1.
????? Response.Write(“<script language=javascript> window.alert(‘保存成功1’);</script>”);
?? 2.
????? Response.Write(“<script>alert(‘”+”保存成功!”+”‘);</script>”);
?? 3.
????? this.Page.RegisterStartupScript(“ChiName”,”<script language=’javascript’>alert(‘” + “保存成功!” + “‘)</script>”);
(五).DataGrid中加CheckBox控件模板列.
?? 請看:? http://blog.csdn.net/chengking/archive/2005/10/08/497520.aspx
(六). window.open() 方法
語法:window.open(pageurl,name,parameters);
window對象的open()方法用于創建一個新的窗口實例,新創建的窗口的外觀由參數:parameters指定。新窗口中打開的文檔由參數:
?????? pageurl指定。系統能夠根據參數:name確定的名稱訪問該窗口。
??????? 下表為parameters參數表:
??????? 參數????????? 衩始值?????????? 說明
??????? alwaysLowered yes/no 指定窗口隱藏在所有窗口之下。
??????? alwaysRaised yes/no 指定窗口浮在所有窗口之上。
??????? dependent yes/no 指定打開的窗口為父窗口的一個了窗口。并隨父窗口的關閉而關閉。
??????? directions yes/no 指定Navigator 2和3的目錄欄是否在新窗口中可見。
??????? height pixel value 設定新窗口的像素高度。
??????? hotkeys yes/no 在沒有菜單欄的新窗口設置安全退出熱鍵。
??????? innerHeight pixel value 設置新窗口中文檔的像素高度。
??????? innerWidth pixel value 設置新窗口中文檔的像素寬度。
??????? location yes/ no 指明位置欄在新窗口中是否可見。
??????? menubar yes /no 指明菜單欄在新窗口中是否可見。
??????? outerHeight pixel value 設定窗口(包括裝飾邊框)的像素高度。
??????? outerWidth pixel value 設定窗口(包括裝飾邊框)的像素寬度。
??????? resizable yes /no 指明新窗口是否可以調整。
??????? screenX pixel value 設定新窗口離屏幕邊界的像素長度。
??????? screenY pixel value 設定新窗口離屏幕上邊界的像素長度。
??????? scrollbars yes /no 指明滾動欄在新窗口中是否可見。
??????? titlebar yes /no 指明菜單題目欄在新窗口是否可見。
??????? toolbar yes /no 指明工具欄在新窗口中是否可見。
??????? Width pixel value 設定窗口的像素寬度。
??????? z-look yes /no 在文檔中包含各個<pplet>標簽的數組。
??????? fullscreen yes / no 打開的窗體是否進行全屏顯示
??????? left pixel value 設定新窗口距屏幕左方的距離
??????? top pixel value 設定新窗口距屏幕上方的距離
?
?????? 例子:
??????? <html>
?????????? <head>
?????????????? <title>window.open函數</title>
?????????? </head>
?????????? <body>
????????????? <script language=”javascript”>
?????????????????? <!–
???????????????? window.open(“”,”name1″,”width=100,height=200,toolbar=no,scrollbars=no,menubar=no,screenX=100,screenY=100″);
??????????????????? //–>
????????????? </script>
?????????? </body>
??????? </html>
(七).location對象
??? href 整個URL字符串.
??? protocol 含有URL第一部分的字符串,如http:
??? host 包含有URL中主機名:端口號部分的字符串.如//www.cenpok.net/server/
??? hostname 包含URL中主機名的字符串.如http://www.cenpok.net
??? port 包含URL中可能存在的端口號字符串.
??? pathname URL中”/”以后的部分.如~list/index.htm
??? hash “#”號(CGI參數)之后的字符串.
??? search “?”號(CGI參數)之后的字符串.
(八).按鍵捕捉
?? 1.Ctrl+Enter按鍵捕捉方法
??? <body onkeydown=”doKeyDown()”>
??? <script language=”JavaScript”>
??? <!–
??? function doKeyDown()
???? {
??????? if (event.ctrlKey && event.keyCode == 13)
???????? {
?????????? alert(“You pressed the Ctrl + Enter”)
???????? }
???? }
??? //–>
??? </script>
??? </body>
?? 2.Alt加快捷鍵: Alt+A
???? <button accessKey=A title=”Alt+A” onclick=”alert(‘Button clicked!’)”>Alt+A</button>
(九).控制輸入,非法字符不能輸入到TextBox.
??? <asp:textbox class=”Text”
??????? onkeypress=”if (event.keyCode < 48 || event.keyCode >57) event.returnValue = false;”
?id=”txtY_Revenue” style=”TEXT-ALIGN: right” runat=”server” Width=”90%” MaxLength=”12″>
??? </asp:textbox>
??? 說明: 此方法控制TextBox只收數字:0~9 , 也自可以定義其它可輸入字符,如改成: 65~123,只允許輸入: a~z和A~Z 等.
