asp.net常用的javascript經典例子

來源:互聯網
上載者:User

Dropdownlist無重新整理的例子。xml.

例如文本驗證!

下面是一個單選按紐前台不重新整理的例子.有好的就往上貼

<script language="javascript">

   function SetButton()  

   {

    if(document.all.rdoByHuman.checked==true)

    {

     document.all.cboHrPut.disabled = "";

     document.all.cboAnswerHr.disabled = "";

     document.all.cboGroup.disabled = true;

    }

    if(document.all.rdoByGroup.checked==true)

    {

     document.all.cboHrPut.disabled = true;

     document.all.cboAnswerHr.disabled = true;

     document.all.cboGroup.disabled = "";

    }

   }

 </script>

<asp:RadioButton id="rdoByHuman" onclick="SetButton();" runat="server" GroupName="TotalGroup" Checked="True" Text="按人員"></asp:RadioButton>

e.Item.Attributes.Add("onmouseOver","this.style.backgroundColor='#dee3e7'");//滑鼠移上去的顏色

   e.Item.Attributes.Add("onmouseOut","this.style.backgroundColor='white'");

   e.Item.Cells[2].Attributes.Add("onmouseOver","this.style.backgroundColor='red'");

   e.Item.Cells[2].Attributes.Add("onmouseOut","this.style.backgroundColor='white'");//指定某列的顏色

   e.Item.Cells[3].Style["cursor"]="hand";

   e.Item.Cells[4].Attributes.Add("onclick","alert('你惦記的ID 是:"+e.Item.Cells[4].Text+"');");//指定顯示欄位

  e.Item.Cells[1].Attributes.Add("title","'紅孩是未解決的,藍精靈是已解決的!'"+e.Item.Cells[0].Text.ToString());//顯示title

   e.Item.Cells[0].Attributes.Add("onclick","window.open('xinxiForm.aspx?idmain="+e.Item.Cells[0].Text+"','','ToolBar=no,width=260,height=200');");

屏閉一些鍵:

function KeyDown(){   //屏蔽滑鼠右鍵、Ctrl+n、shift+F10、F5重新整理、退格鍵

   //alert("ASCII代碼是:"+event.keyCode);

 if ((window.event.altKey)&&

      ((window.event.keyCode==37)||   //屏蔽 Alt+ 方向鍵←

       (window.event.keyCode==39))){ //屏蔽 Alt+ 方向鍵→

     alert("不準你使用ALT+方向鍵前進或後退網頁!");

     event.returnValue=false;

     }

 if ((event.keyCode==8) ||                 //屏蔽退格刪除鍵

      (event.keyCode==116)||                 //屏蔽 F5 重新整理鍵

      (event.keyCode==112)||                 //屏蔽 F1 重新整理鍵

      (event.ctrlKey && event.keyCode==82)){ //Ctrl + R

     event.keyCode=0;

     event.returnValue=false;

     }

 if ((event.ctrlKey)&&(event.keyCode==78))   //屏蔽 Ctrl+n

     event.returnValue=false;

 if ((event.shiftKey)&&(event.keyCode==121)) //屏蔽 shift+F10

     event.returnValue=false;

 if (window.event.srcElement.tagName == "A" && window.event.shiftKey) 

      window.event.returnValue = false; //屏蔽 shift 加滑鼠左鍵新開一網頁

 if ((window.event.altKey)&&(window.event.keyCode==115)){ //屏蔽Alt+F4

      window.showModelessDialog("about:blank","","dialogWidth:1px;dialogheight:1px");

      return false;}

}

1. oncontextmenu="window.event.returnvalue=false"   將徹底屏蔽滑鼠右鍵 

2. <body onselectstart="return false">        取消選取、防止複製 

3. onpaste="return false"               不準粘貼 

4. oncopy="return false;" oncut="return false;"    防止複製;防止剪下

5. <link rel="Shortcut Icon" href="favicon.ico"> IE地址欄前換成自己的表徵圖 

6. <link rel="Bookmark" href="favicon.ico">     可以在收藏夾中顯示出你的表徵圖 

7. <input style="ime-mode:disabled">             關閉IME

8. 永遠都會帶著架構 

<script language="javascript"><!-- 

 if (window==top)

 top.location.href="frames.htm"; file://frames.htm為框架頁 

// --></script>

9. 防止被人frame 

<SCRIPT LANGUAGE=javascript><!--  

 if (top.location!=self.location)

 top.location=self.location; 

// --></SCRIPT> 

10. <noscript><iframe src=*.html></iframe></noscript>  網頁將不能被另存新檔

使用滑鼠拖動的層

<BODY BGCOLOR="#FFFFFF">

<div onmousedown="style.cursor='move';startMove(this)" onmouseup="style.cursor='auto'" style="border:1px solid #AAAAAA;background-color:#EEEEEE;width:300;height:200;position;text-align:center;">可以使用滑鼠拖動</div>

<script language=javascript>

function startMove(objDiv)

{

 document.attachEvent("onmousemove",moveDiv);

 document.attachEvent("onmouseup",endMove);

 document.attachEvent("onselectstart",selectNo);

 document["moveDiv"] = objDiv;

 document["startX"] = event.x;

 document["startY"] = event.y;

 document["oldX"] = objDiv.getBoundingClientRect().left;

 document["oldY"] = objDiv.getBoundingClientRect().top;

}

function moveDiv()

{

 //try{

 var obj = document["moveDiv"];

 if(obj)

 {

 var l = document["oldX"];//obj.getBoundingClientRect().left;//obj.style.left// = 100//(event.x-document["startX"]);

 var t = document["oldY"];//obj.getBoundingClientRect().top;//obj.style.top// = 100//(event.y-document["startY"]);

 obj.style.position = "absolute";

 obj.style.left = l + (event.x-document["startX"]);

 obj.style.top = t + (event.y-document["startY"]);

 }

 //}catch(e){endMove();}

}

function endMove()

{

 document.detachEvent("onmousemove",moveDiv);

 document.detachEvent("onmouseup",endMove);

 document.detachEvent("onselectstart",selectNo);

 document["moveDiv"] = null;

 document["startX"] = null;

 document["startY"] = null;

}

function selectNo()

{ return false; }

</script>

</BODY>

/* 非同步,動態載入網頁xml資料 */

//實際運用有更改

function GetXml(objContainer,id){

 var XmlHttp=new ActiveXObject("Microsoft.XMLHTTP")

 objContainer.innerHTML=StateXML(Config.loading)

 objContainer.send="true"

 XmlHttp.onreadystatechange=function(){

 if(XmlHttp.readyState==4){

   if(XmlHttp.status==200){

   var Xmldoc=XmlHttp.responseXML

    if(Xmldoc.documentElement.hasChildNodes())

    objContainer.innerHTML=Xmldoc.transformNode(xsldoc)

    else

    objContainer.innerHTML=StateXML(Config.loading)

   }

   else

   objContainer.innerHTML=StateXML(Config.unavaible)

 }

 }

 XmlHttp.open("get",Config.Service+'?id='+id+'&tem'+Math.random(),true)

 XmlHttp.send()

}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.