html js 常用

来源:互联网 发布:网络语晕针是什么意思 编辑:程序博客网 时间:2024/05/13 08:11

 1.自动选定文本框中的文本
<input type="text" name="mtext" size="100" width=20 value="待选中的文本,把鼠标移上去看看:)" onmouseover="focus();select();">


2.输入框限制
<input type="text" name="txtMonth" value=""
    onBlur="if(this.value<1||this.value>12)
    {alert('月份输入有误!');
    this.focus();}>


3.限制输入框只能输入数字金额
<input type=text name=txtPostalCode onKeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnvalue = false;">

4.回车转下一行
<input onkeydown="if(event.keyCode==13)event.keyCode=9" name="text1">

5.弹出普通窗口及全屏展开
<script language="javascript" type="text/javascript">
var winH=window.screen.height -58;
var winW=window.screen.width -10;
</script>
<A href='javascript:;' onclick="window.open('search_grmx.asp?sid=<%=rs("sid")%>&rq_year=<%=year(rs("rq"))%>&rq_month=<%=month(rs("rq"))%>','newwindow','scrollbars=yes,top=1,left=1,width='+winW+',height='+winH+'')">链接文字
</a>
6.JS验证
<SCRIPT language=javascript>
<!--
function checkform()
{
  if (document.form1.skr.value=="") {
    alert("必须输入");
 form1.skr.focus();
 return false;  
  }
  return true;
}
//-->
</SCRIPT>

<form name="form1" method="post" action="enter.asp" onsubmit="return checkform();">

7.全选删除
<script language="javascript">
<!-- Begin
 var checkflag = "false";
 function check(field) {
  if (checkflag == "false") {
   for (i = 0; i < field.length; i++){
    if (field[i].disabled == false){
     field[i].checked = true;
    }
   }
   checkflag = "true";
   return "取消全选";
  }
  else {
   for (i = 0; i < field.length; i++){
    field[i].checked = false;
   }
   checkflag = "false";
   return "全 选";
  }
 }
//  End -->
</script>

<input type="checkbox" name="list" value="<%=PIC_ID%>">

<input name="button" type=button onClick="this.value=check(this.form.list)" class="bottom" value="全 选">
<input name="Submit" type=submit  class="bottom" value="删 除">

8. text聚焦
<body text="#000000" bgcolor="#EFF1FD" onload="document.form1.txm.focus();" scroll="no">

9.限制只能输入(0~9,a~z)﹕
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
    <SCRIPT language=javascript>
<!--
function ischinese(){
var reg=/[^a-z0-9_]/g
if (reg.test(document.form1.text3.value)){
    alert("请输入0-9和小写的a-z﹗");
 form1.text3.focus();
return false;
}else{
return true;}
}
//-->
</SCRIPT>

</head>

<body>
<FORM name="form1" method="post" action="abc.asp" onsubmit="return ischinese();">
<input name="text3" type="text" size="15" value="">
  <input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>
 
 
限制输入框只能输入数字金额
<input type=text name=txtPostalCode onKeypress="if (event.keyCode < 45 || event.keyCode > 57) event.returnvalue = false;">

1.  oncontextmenu="window.event.returnvalue=false"      将彻
底屏蔽鼠标右键
    <table border oncontextmenu=return(false)><td>no</table>
  可用于Table
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";
//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>     网
页将不能被另存为
11. <input type=button value=查看网页源代码
 onclick="window.location = 'view-source:'+
' http://www.csdn.net/&#39;">
12. 怎样通过asp的手段来检查来访者是否用了代理
<% if Request.ServerVariables("HTTP_X_FORWARDED_FOR")<>""
then
 response.write "<font color=#FF0000>您通过了代理服务器,"&
_
 "真实的IP为
"&Request.ServerVariables("HTTP_X_FORWARDED_FOR")
 end if
%>
13. 取得控件的绝对位置
//javascript
<script language="javascript">
function getIE(e){
  var t=e.offsetTop;
  var l=e.offsetLeft;
  while(e=e.offsetParent){
    t+=e.offsetTop;
    l+=e.offsetLeft;
    }
  alert("top="+t+"/nleft="+l);
  }
</script>
//VBScript
<script language="VBScript"><!--
function getIE()
  dim t,l,a,b
  set a=document.all.img1
  t=document.all.img1.offsetTop
  l=document.all.img1.offsetLeft
  while a.tagName<>"BODY"
    set a = a.offsetParent
    t=t+a.offsetTop
    l=l+a.offsetLeft
  wend
  msgbox "top="&t&chr(13)&"left="&l,64,"得到控件的位置"
end function
--></script>
14. 游标是停在文本框文字的最后
<script language="javascript">
function cc()
{
  var e = event.srcElement;
  var r =e.createTextRange();
  r.moveStart('character',e.value.length);
  r.collapse(true);
  r.select();
}
</script>
<input type=text name=text1 value="123" onfocus="cc()">
15. 判断上一页的来源
asp:
request.servervariables("HTTP_REFERER")
javascript:
document.referrer
16. 最小化、最大化、关闭窗口
<object id=hh1
classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">
<param name="Command" value="Minimize"></object>
<object id=hh2
classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">
<param name="Command" value="Maximize"></object>
<OBJECT id=hh3
classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">
<PARAM NAME="Command" value="Close"></OBJECT>
<input type=button value=最小化 onclick=hh1.Click()>
<input type=button value=最大化 onclick=hh2.Click()>
<input type=button value=关闭 onclick=hh3.Click()>
本例适用于IE

解决内容把表格撑大的问题

td style="word-break:break-all">

 
打印分页﹕<br clear=all style='page-break-before:always'>

表格撑大的问题
 
 
javascript表单提交限制 
 
 
 
作者:admin 文章来源:本站原创 点击数:2719 更新时间:2004-9-11
 
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<SCRIPT language=javascript>
<!--
function checkform()
{
  if (document.form1.xm.value=="") {
    alert("请输入姓名!");
 form1.xm.focus();
 return false;  
  }
  return true;
}
//-->
</SCRIPT>
</head>
<body onLoad="document.form1.xm.focus();">
<FORM name="form1"  action="abc.asp" method="post" onsubmit="return checkform();">
  <p>姓名
    <input name="xm" type="text" id="xm">
  </p>
  <p>
    <input type="submit" name="Submit" value="提交">
  </p>
</form>
</body>
</html>
======================================================================
网页上显示时间的最简单的Javascript代码
<div id="webjx">
<script>
setInterval("webjx.innerHTML=new Date().toLocaleString()+' 星期'+'日一二三四五六'.charAt(new Date().getDay());",1000);
</script>
</div>