asp.net常用的javascript经典例子

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+nshift+F10F5刷新、退格键

   //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">             关闭输入法

 

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()

}

你可能感兴趣的:(JavaScript)