有用的13种js代码!

来源:互联网 发布:linux cacti 编辑:程序博客网 时间:2024/06/06 03:46

1、隐藏状态栏里出现的LINK信息
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Default2.aspx" Style="z-index: 103;
            left: 16px; position: absolute; top: 512px" onMouseOver="window.status='none';return true" onMouseDown="window.status='none';return true">HyperLink</asp:HyperLink>
2、右键屏蔽
<body oncontextmenu=self.event.returnValue=false>
3、调用服务器控件的属性
var radios = document.getElementsByName("RadioButtonList");
for(var i=0;i<radios.length;i++)
{
    if(radios[i].checked)
   {

 alert("当前selectedIndex="+i);
}
}
4、后台调用前台的javascript函数
(1)、前台定义函数
<script  type="text/javascript">
function aaa()
{
for(i=0;i<10;i++)
{
 alert("当前______FUCK!");
}
}
</script>
(2)、后台引用
Button1.Attributes.Add("OnClick", "aaa()");
5、屏蔽JAVASCRIPT错误
<script language="JavaScript">
<!--
function killErrors(){
return true;
}
window.onerror = killErrors;
-->
</script>
6、检查一段字符串是否全由数字组成
<script language="Javascript"><!--
function checkNum(str){return str.match(//D/)==null}
alert(checkNum("1232142141"))
alert(checkNum("123214214a1"))
// --></script>
7、判断是否是字符
if (/[^/x00-/xff]/g.test(s)) alert("含有汉字");
8、让超链接不显示下划线

  <style type="text/css">   
<!-   
a:link{text-decoration:none}   
a:hover{text-decoration:none}   
a:visited{text-decoration:none}   
->   
</style>
9、设置该页为首页

<body bgcolor="#FFFFFF" text="#000000">   
<!-- 网址:http://你的网址-->   
<a class="chlnk" style="cursor:hand" HREF onClick="this.style.behavior=&apos;&apos;url(#default#homepage)&apos;&apos;; this.setHomePage(&apos;&apos;你的网站名称);"><font color="000000" size="2" face="宋体">设为首页</font></a>   
</body>

10、节日倒计时
<Script Language="javascript">   
var timedate= new Date("December 25,2003");   
var times="圣诞节";   
var now = new Date();   
var date = timedate.getTime() - now.getTime();   
var time = Math.floor(date / (1000 * 60 * 60 * 24));   
if (time >= 0)   
document.write("现在离"+times+"还有: "+time +"天");
</Script>
11、显示系统当前日期
<script language=javascript>   
today=new Date();   
function date(){   
this.length=date.arguments.length   
for(var i=0;i<this.length;i++)   
this[i+1]=date.arguments
}   
var d=new date("星期日","星期一","星期二","星期三","星期四","星期五","星期六");   
document. write(   "<font color=##000000 style=&apos;&apos;font-size:9pt;font-family: 宋体&apos;&apos;> ", today.getYear(),"年",today.getMonth()+1,"月",today.getDate(),"日",d [today.getDay()+1],"</font>" );   
</script>
12、加入收藏
<INPUT name=Button2 onclick="window.external.AddFavorite(location.href, document.title)" type=button value=加入收藏夹>
13、禁止选取<body oncontextmenu="return false" ondragstart="return false" onselectstart ="return false" onselect="document.selection.empty()" oncopy="document.selection.empty()" onbeforecopy="return false"onmouseup="document.selection.empty()>