JavaScript案例1

(一).確認刪除用法: 

  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"> 



  4.關閉本彈出窗體,並刷新父頁面 



      this.Response.Write(" <script language='javascript'>window.opener.location.reload();window.close(); </script>"); 





(四).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參數)之後的字符串. 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章