常用JS代码集

 

只能是写限定的东西 代码如下: 

  ENTER键可以让光标移到下一个输入框 

< input onkeydown = " if(event.keyCode==13)event.keyCode=9 "   >

  只能是中文

< input onkeyup = " value=value.replace(/[ -~]/g,'') "  onkeydown = " if(event.keyCode==13)event.keyCode=9 " >

  只能是英文和数字.屏蔽了输入法

< input style = " ime-mode:disabled "  onkeydown = " if(event.keyCode==13)event.keyCode=9 " >

  只能输入英文和数字

< input onkeyup = " value=value.replace(/[W]/g,'')  " onbeforepaste = " clipboardData.setData('text',clipboardData.getData('text').replace(/[^d]/g,'')) "  onkeydown = " if(event.keyCode==13)event.keyCode=9 " >

  只能是数字

< input onkeyup = " value=value.replace(/[^d]/g,'')  " onbeforepaste = " clipboardData.setData('text',clipboardData.getData('text').replace(/[^d]/g,'')) " >

  只能显示,不能修改的文本框

< input readOnly value = " 只能显示,不能修改 " >

  只能是数字,判断按键 代码如下:

< script  language = javascript >
function   onlyNum()
{
if(!((event.keyCode>=48&&event.keyCode<=57)||(event.keyCode>=96&&event.keyCode<=105)||(event.keyCode==8)))
event.returnValue
=false;
}

</ script >
< input  onkeydown = " onlyNum(); " >   

  附:获取键盘的KeyCode

< html >
< head >
< script language = " javascript " >
  ns4 
=  (document.layers)  ?   true  :  false ;
  ie4 
=  (document.all)  ?   true  :  false ;
function  keyDown(e) {
  
if(ns4){
  
var nkey=e.which;
  
var iekey='现在是ns浏览器';
  
var realkey=String.fromCharCode(e.which);
}

  
if(ie4){
  
var iekey=event.keyCode;
  
var nkey='现在是ie浏览器';
  
var realkey=String.fromCharCode(event.keyCode);
  
if(event.keyCode==32){realkey='' 空格''}
  
if(event.keyCode==13){realkey='' 回车''}
  
if(event.keyCode==27){realkey='' Esc''}
  
if(event.keyCode==16){realkey='' Shift''}
  
if(event.keyCode==17){realkey='' Ctrl''}
  
if(event.keyCode==18){realkey='' Alt''}
}

  alert(
'ns浏览器中键值:'+nkey+' '+'ie浏览器中键值:'+iekey+' '+'实际键为'+realkey);
}

document.onkeydown 
=  keyDown;
if (ns4) {
document.captureEvents(Event.KEYDOWN);}

</ script >
</ head >
< body >
// Javascript Document.
< hr >
< center >
< h3 > 请按任意一个键。。。。 </ h3 >
</ center >
</ body >
</ html >

  限制网页用键盘

< body onkeydown = " alert('禁用');return false; " >

  限制键盘的某个键:

< body onkeydown = " if(event.keyCode==num){alert('禁用');return false;}>

  再加个找按键的值

<script>
function show(){
  alert(
" ASCII代码是: " +event.keyCode);
}
</script>
<body οnkeydοwn=
" show() " >

  只能是IP地址

<html>

<head>
<meta http-equiv=
" Content - Type "  content= " text / html; charset = gb2312 " >
<meta name=
" GENERATOR "  content= " Microsoft FrontPage  4.0 " >
<meta name=
" ProgId "  content= " FrontPage.Editor.Document " >
<style>
.a3{width:30;border:0;text-align:center}
</style>
<script>
function mask(obj){
obj.value=obj.value.replace(/[^d]/g,'')
key1=event.keyCode
if (key1==37 || key1==39)
{ obj.blur();
nextip=parseInt(obj.name.substr(2,1))
nextip=key1==37?nextip-1:nextip+1;
nextip=nextip>=5?1:nextip
nextip=nextip<=0?4:nextip
eval(
" ip " +nextip+ " .focus() " )

if(obj.value.length>=3) 
if(parseInt(obj.value)>=256 || parseInt(obj.value)<=0)
{
alert(parseInt(obj.value)+
" IP地址错误! " )
obj.value=
""
obj.focus()
return false;
}
else 
{ obj.blur();
nextip=parseInt(obj.name.substr(2,1))+1
nextip=nextip>=5?1:nextip
nextip=nextip<=0?4:nextip
eval(
" ip " +nextip+ " .focus() " )
}
}
function mask_c(obj)
{
clipboardData.setData('text',clipboardData.getData('text').replace(/[^d]/g,''))
}

</script>
<title>IP地址输入</title>

</head>
<body>IP地址输入
<div style=
" border - width: 1 ;border - color:balck;border - style:solid;width: 165 ;font - size:9pt " >
<input type=text name=ip1 maxlength=3 class=a3 οnkeyup=
" mask( this ) "  onbeforepaste=mask_c()>.
<input type=text name=ip2 maxlength=3 class=a3 οnkeyup=
" mask( this ) "  onbeforepaste=mask_c()>.
<input type=text name=ip3 maxlength=3 class=a3 οnkeyup=
" mask( this ) "  onbeforepaste=mask_c()>.
<input type=text name=ip4 maxlength=3 class=a3 οnkeyup=
" mask( this ) "  onbeforepaste=mask_c()>
</div>
</body>

</html>

  用#default#savehistory防止后退清空text文本框: 

<HTML>
<HEAD>
<META NAME=
" save "  CONTENT= " history " >
<STYLE>
  .saveHistory {behavior:url(#default#savehistory);}
</STYLE>
</HEAD>
<BODY>
<INPUT class=saveHistory type=text id=oPersistInput>
<input type=button οnclick='javascript:location.href=
" http: // www.webjx.com/"' value='点击进入,再按后退键试试?'>
</ BODY >
</ HTML >

  TEXTAREA自适应文字行数的多少

< textarea rows = 1  name = s1 cols = 27  onpropertychange = " this.style.posHeight=this.scrollHeight " >  

  上传预览图片

< img id = pic  src = http: // www.webjx.com/images/logo.gif>
< input type = file name = file >< input type = button onclick = pic.src = file.value value = 预览图片 >
< input type = button onclick = alert(file.value) value = 图片地址 >
< input type = button onclick = " file.outerHTML=file.outerHTML.replace(/value=w/g,'') "  value = " 清除file里字 " >

  去掉下拉选项的边框

< div style = " position: absolute; left: 10px; top: 10px; width: 115px; height: 20px;  clip:rect(2 114 20 2); " >  
   
< select >
    
< option  > cnpeople </ option >
    
< option  > cnrose </ option >
   
< option  > cnbruce </ option >   
  
</ select >
  
</ font >
</ div >

  下拉列表打开窗口

< select  onChange = " if(this.selectedIndex && this.selectedIndex!=0){window.open(this.value);}this.selectedIndex=0; " >
< option selected > 更多链接…… </ option >
< option value = " http://www.cnbruce.com " > cnbruce </ option >
< option value = " http://daonet.myrice.com/old/ " > daonet </ option >
< option value = " http://www.blueidea.com " > blue ! dea
</ select >

  TAB的显示

< script >
function  editTab()
{
    
var code, sel, tmp, r
    
var tabs=""
    event.returnValue 
= false
    sel 
=event.srcElement.document.selection.createRange()
    r 
= event.srcElement.createTextRange()

    
switch (event.keyCode)
    
{
        
case (8)    :
            
if (!(sel.getClientRects().length > 1))
            
{
                event.returnValue 
= true
                
return
            }

            code 
= sel.text
            tmp 
= sel.duplicate()
            tmp.moveToPoint(r.getBoundingClientRect().left, sel.getClientRects()[
0].top)
            sel.setEndPoint(
"startToStart", tmp)
            sel.text 
= sel.text.replace(/^ /gm, "")
            code 
= code.replace(/^ /gm, "").replace(/ /g, " ")
            r.findText(code)
            r.select()
            
break
        
case (9)    :
            
if (sel.getClientRects().length > 1)
            
{
                code 
= sel.text
                tmp 
= sel.duplicate()
                tmp.moveToPoint(r.getBoundingClientRect().left, sel.getClientRects()[
0].top)
                sel.setEndPoint(
"startToStart", tmp)
                sel.text 
= " "+sel.text.replace(/ /g, " ")
                code 
= code.replace(/ /g, " ")
                r.findText(code)
                r.select()
            }

            
else
            
{
                sel.text 
= " "
                sel.select()
            }

            
break
        
case (13)    :
            tmp 
= sel.duplicate()
            tmp.moveToPoint(r.getBoundingClientRect().left, sel.getClientRects()[
0].top)
            tmp.setEndPoint(
"endToEnd", sel)

            
for (var i=0; tmp.text.match(/^[ ]+/g) && i<tmp.text.match(/^[ ]+/g)[0].length; i++)    tabs += " "
            sel.text 
= " "+tabs
            sel.select()
            
break
        
default        :
            event.returnValue 
= true
            
break
    }

}

</ script >

< textarea  cols = 75   rows = 20   onkeydown = " editTab() " >
< script >
alert(
" ok " )
</ script >
</ textarea >

  文本框的上
/ 下拉

< form name = " cnbruce " >
< textarea name = " com " >
</ textarea >
</ form >
< SPAN title = ' 放大输入框 '  style = ' FONT-SIZE: 12px; CURSOR: hand '   onclick = document.cnbruce.com.rows += 4 > 向下 </ SPAN >
 
< SPAN title = ' 缩小输入框 '  style = ' FONT-SIZE: 12px; CURSOR: hand '  class = ' arrow '  onclick = ' if(document.cnbruce.com.rows>=4)document.cnbruce.com.rows-=4;else return false ' > 向上 </ SPAN >

  一个复选框,点击之后一组复选框全部都选上

< input type = " checkbox "  name = " checkA "  onpropertychange = " for(i=0;i<A.children.length;i++){A.children[i].checked=this.checked} " > a
< br >
< span id = " A " >
< input type = " checkbox "  name = " A1 " >
< input type = " checkbox "  name = " A2 " >
< input type = " checkbox "  name = " A3 " >
</ span >

  Debug Textarea:在线写 js 脚本的时候,用来即时查错的东西!

< HTML >
< HEAD >
< TITLE > Debug Textarea </ TITLE >
< meta http - equiv = ' Content-Type '  content = ' text/html; charset=gb2312 ' >
</ HEAD >
< style >
*   {
    font
-size: 12px
}

body 
{
    margin: 10px; padding: 0px
}

table.list
{
    cursor: 
default;
    border:1px solid #cccccc
    background
-color: #cccccc;
    border
-collapse: collapse;
    border
-Color: #cccccc;
}

</ style >
< script language = " javascript " >
//  Coded by windy_sk <windy_sk@126.com> 20040205

function  reportError(msg,url,line)  {
    
var str = "You have found an error as below:  ";
    str 
+= "Err: " + msg + " on line: " + line;
    alert(str);
    
return true;
}


window.onerror 
=  reportError;

document.onkeydown 
=   function ()  {
    
if(event.ctrlKey){
        
switch(event.keyCode) {
            
case 82//r
                runcode();
                
break;
            
case 83//s
                savecode();
                
break;
            
case 71//g
                goto(prompt('Please input the line number''1'));
                
break;
            
case 65//a
                document.execCommand("SelectAll");
                
break;
            
case 67//c
                document.execCommand("Copy");
                
break;
            
case 88//x
                document.execCommand("Cut");
                
break;
            
case 86//v
                document.execCommand("Paste");
                
break;
            
case 90//z
                document.execCommand("Undo");
                
break;
            
case 89//y
                document.execCommand("Redo");
                
break;
            
default:
                
break;
        }

        event.keyCode 
= 0;
        event.returnValue 
= false;
    }

    
return;
}


function  show_ln() {
    
var txt_ln     = document.getElementById('txt_ln');
    
var txt_main     = document.getElementById('txt_main');
    txt_ln.scrollTop 
= txt_main.scrollTop;
    
while(txt_ln.scrollTop != txt_main.scrollTop) {
        txt_ln.value 
+= (i+++ ' ';
        txt_ln.scrollTop 
= txt_main.scrollTop;
    }

    
return;
}


function  editTab() {
    
var code, sel, tmp, r
    
var tabs=''
    event.returnValue 
= false
    sel 
=event.srcElement.document.selection.createRange()
    r 
= event.srcElement.createTextRange()

    
switch (event.keyCode){
        
case (8)    :
            
if (!(sel.getClientRects().length > 1)){
                event.returnValue 
= true
                
return
            }

            code 
= sel.text
            tmp 
= sel.duplicate()
            tmp.moveToPoint(r.getBoundingClientRect().left, sel.getClientRects()[
0].top)
            
// 出错检验代码~~~~~~
            if(sel.parentElement() != tmp.parentElement()) return;
            sel.setEndPoint(
'startToStart', tmp)
            sel.text 
= sel.text.replace(/^ /gm, '')
            code 
= code.replace(/^ /gm, '').replace(/ /g, ' ')
            r.findText(code)
            r.select()
            
break
        
case (9)    :
            
if (sel.getClientRects().length > 1){
                code 
= sel.text
                tmp 
= sel.duplicate()
                tmp.moveToPoint(r.getBoundingClientRect().left, sel.getClientRects()[
0].top)
                
// 出错检验代码~~~~~~
                if(sel.parentElement() != tmp.parentElement()) return;
                sel.setEndPoint(
'startToStart', tmp)
                sel.text 
= ' '+sel.text.replace(/ /g, ' ')
                code 
= code.replace(/ /g, ' ')
                r.findText(code)
                r.select()
            }
else{
                sel.text 
= ' '
                sel.select()
            }

            
break
        
case (13)    :
            tmp 
= sel.duplicate()
            tmp.moveToPoint(r.getBoundingClientRect().left, sel.getClientRects()[
0].top)
            
// 出错检验代码~~~~~~
            if(sel.parentElement() != tmp.parentElement()) return;
            tmp.setEndPoint(
'endToEnd', sel)
            
for (var i=0; tmp.text.match(/^[ ]+/g) && i<tmp.text.match(/^[ ]+/g)[0].length; i++)    tabs += ' '
            sel.text 
= ' '+tabs
            sel.select()
            
break
        
default        :
            event.returnValue 
= true
            
break;
    }

    
return;
}


function  runcode()  {
    
var str = document.getElementById("txt_main").value;
    
var code_win = window.open('about:blank');
    code_win.document.open();
    code_win.document.writeln(
"<script>");
    code_win.document.writeln(
"function reportError(msg,url,line){ line-=14; var str='You have found an error as below: /n/n'; str+='Err: '+msg+' on line: '+(line); alert(str); opener.goto(line); opener.focus(); window.οnerrοr=null; setTimeout('self.close()',10); return true; }");
    code_win.document.writeln(
"window.onerror = reportError;");
    code_win.document.writeln(
"</script>");
    code_win.document.writeln(str);
    code_win.document.close();
    
return;
}


function  savecode()  {
    
var str = document.getElementById("txt_main").value;
    
var code_win = window.open('about:blank','_blank','top=10000');
    code_win.document.open();
    code_win.document.writeln(str);
    code_win.document.close();
    code_win.document.execCommand(
'saveas','','code.html');
    code_win.close();
    
return;
}


function  goto(ln)  {
    
if(!/^d+$/.test(ln)) return;
    
var obj = document.getElementById("txt_main");
    
var rng = obj.createTextRange();
    
var arr = obj.value.replace(/ /"").split(/ /);
    
if(ln>arr.length) ln = arr.length;
    
var str_tmp = "";
    
for(var i=0; i<ln-1; i++{
        str_tmp 
+= arr[i];
    }

    rng.moveStart(
'character',str_tmp.length+1);
    str_tmp 
= "";
    
for(i=ln; i<arr.length; i++{
        str_tmp 
+= arr[i];
    }

    rng.moveEnd(
'character',-str_tmp.length); 
    rng.select();
    
return;
}


window.onload 
=   function ()  {document.getElementById("txt_main").value = "<script> alert(') </script>";}
</ script >
< BODY >
< table width = ' 600 '  class = ' list '  border = ' 1 '  bgcolor = ' #eeeeee '  bordercolorlight = ' #000000 '  bordercolordark = ' #FFFFFF '  cellpadding = ' 0 '  cellspacing = ' 0 ' >
  
< tr bgcolor = ' #cccccc ' >  
    
< td colspan = ' 2 '  height = ' 20 '  align = ' center ' >< b > Debug Textarea </ b ></ td >
  
</ tr >
  
< tr >  
    
< td colspan = ' 2 ' >
        
< table width = ' 95% '  border = ' 0 '  align = ' center '   >
      
< tr >  
        
< td align = ' center ' >< br  />
          
< textarea id = ' txt_ln '  name = ' content '  rows = ' 10 '  style = ' width:40px;overflow:hidden;height:200px;border-right:0px;text-align:right;line-height:14px '  onselectstart = ' this.nextSibling.focus();return false '  readonly ></ textarea >< textarea id = ' txt_main '  name = ' content '  rows = ' 10 '  cols = ' 80 '  onkeydown = ' editTab() '  onkeyup = ' show_ln() '  onscroll = ' show_ln() '  wrap = ' off '  style = ' overflow:auto;height:200px;padding-left:5px;border-left:0px;line-height:14px ' ></ textarea >
          
< script > for ( var  i = 1 ; i <= 20 ; i ++ ) document.getElementById( ' txt_ln ' ).value  +=  i  +   ' ' ; </ script >
        
</ td >
      
</ tr >
          
< tr >  
            
< td align = ' center ' >< br  />
              
< input type = ' button '  value = '  运 行  '  onclick = ' runcode() '  accesskey = ' r ' >& nbsp; & nbsp;
              
< input type = ' button '  value = '  保 存  '  onclick = ' savecode() '  accesskey = ' s ' >& nbsp; & nbsp;
              
< input type = ' button '  value = '  跳 转  '  onclick = " goto(prompt('Please input the line number', '1')) "   accesskey = ' g ' >& nbsp; & nbsp;
            
</ td >
          
</ tr >
        
</ table >
    
</ td >
  
</ tr >
</ table >
</ BODY >
</ HTML >

  获取input的非value值,而是显示文本值

< select name = " sss "  onChange = " alert(this.options[this.selectedIndex].text) " >
< option value = " 1 " > asdf </ option >
< option value = " 2 " > bbbb </ option >
< option value = " 3 " > ccc </ option >
</ select >

  select里的option进行分类列表

< span style = " position:absolute;border:1px inset #d3d6d9 " >< select style = " margin:-2px; width:200px " >
< option selected >------------ 请选择 ------------</ option >
< optgroup label = " JavaScript&VBScript区 " >
 
< option > 原   创
 
< option > 经   典
< optgroup label = " 后台区 " >
 
< option > asp & sql
 
< option > php & mysql
</ select ></ span >

  动态添加

< form name = " myForm "  method = " post " >
< select name = " dept_company "  size = " 10 "  multiple id = " dept_company "  class = " mySelect " >
          
< option value = "" > Please Select... </ option >
          
< option value = " a " > AA </ option >
          
< option value = " b " > BB </ option >
          
< option value = " c " > CC </ option >
        
</ select >< input name = " dept_company_list "  type = " hidden " >
        
< input name = " button "  type = " button "  class = " myButton "  onClick = " addItem('dept_company','dept_company2') "  value = " 添加--&gt;&gt; " >
        
< input name = " button "  type = " button "  class = " myButton "  onClick = " deleteItem('dept_company2','dept_company') "  value = " &lt;&lt;--删除 " >
        
< select name = " dept_company2 "  size = " 10 "  multiple id = " dept_company2 "  class = " mySelect " >
        
</ select >
</ form >
< script >
function  addItem(fromName,toName) {
    eval(
"var obj1=myForm."+fromName);
    eval(
"var obj2=myForm."+toName);
    obj1.options[
0].selected=false;
    
if(obj1.selectedIndex == -1)
        
return false;
    
var tempValue;
    
var tempText;
    
for(var i=1;i<obj1.length;i++)//begin from 1
        if(obj1.selectedIndex == -1)break;
        tempValue
=obj1.options[obj1.selectedIndex].value;
        tempText
=obj1.options[obj1.selectedIndex].text;
        obj1.options[obj1.selectedIndex]
=null;
        obj2.add(
new Option(tempText,tempValue),0); 
    }

}

function  deleteItem(fromName,toName) {
    eval(
"var obj1=myForm."+fromName);
    eval(
"var obj2=myForm."+toName);
    
if(obj1.selectedIndex == -1)
        
return false;
    
var tempValue;
    
var tempText;
    
for(var i=0;i<obj1.length;i++)//begin from 0
        if(obj1.selectedIndex == -1)break;
        tempValue
=obj1.options[obj1.selectedIndex].value;
        tempText
=obj1.options[obj1.selectedIndex].text;
        obj1.options[obj1.selectedIndex]
=null;
        obj2.add(
new Option(tempText,tempValue),1); //addItem index is 1
    }

}

</ script >

  提示限制输入的字符数

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

function  SymError()
{
  
return true;
}


window.onerror 
=  SymError;

function  strlength(str) {
    
var l=str.length;
    
var n=l
    
for (var i=0;i<l;i++)
    
{
        
if (str.charCodeAt(i)<0||str.charCodeAt(i)>255) n++
    }

    
return n        
}


function  changebyte(value,length) {
    
var l=strlength(value)
    
if (l<=length) {
        
if (document.all!=null) document.all("byte").innerText="还可以输入"+(length-l)+"字节"
    }

    
else
    
{
        document.all(
"byte").innerText="输入字节数超出范围"
    }

    
return true
}


function  changebyte1(value,length) {
    
var l=strlength(value)
    
if (l<=length) {
        
if (document.all!=null) document.all("byte1").innerText="还可以输入"+(length-l)+"字节"
    }

    
else
    
{
        document.all(
"byte1").innerText="输入字节数超出范围"
    }

    
return true
}


function  changebyte2(value,length) {
    
var l=strlength(value)
    
if (l<=length) {
        
if (document.all!=null) document.all("byte2").innerText="还可以输入"+(length-l)+"字节"
    }

    
else
    
{
        document.all(
"byte2").innerText="输入字节数超出范围"
    }

    
return true
}

</ script >
< form method = " post "  name = test onSubmit = " return checkdata() "  action = "" >
< TEXTAREA onkeydown = " return changebyte1(document.test.icqcontent.value,198) "  onkeyup = " return changebyte1(document.test.icqcontent.value,198) "  name = icqcontent cols = 40  rows = " 3 " ></ TEXTAREA >
< SPAN id = byte1 >< SCRIPT language = JavaScript > changebyte1(document.test.icqcontent.value, 198 ); </ SCRIPT ></ SPAN >
</ form >

  判断填写字数的限制

< script language = javascript >
function  gbcount(message,total,used,remain)
{
  
var max;
  max 
= total.value;
  
if(message.value.length > max){
    message.value 
= message.value.substring(0,max);
    used.value 
= max;
    remain.value 
= 0;
    alert(
'留言不能超过规定的字数!');
  }

  
else{
    used.value 
= message.value.length;
    remain.value 
= max - used.value;
  }

}

</ script >

< form name = ' myform '   >
< textarea name = ' GuestContent '  cols = ' 59 '  rows = ' 6 '     onkeydown = gbcount( this .form.GuestContent, this .form.total, this .form.used, this .form.remain); onkeyup = gbcount( this .form.GuestContent, this .form.total, this .form.used, this .form.remain); ></ textarea >
最多字数:
< INPUT disabled maxLength = 4  name = total size = 3  value = 20 >
已用字数:
< INPUT disabled maxLength = 4  name = used size = 3  value = 0 >
剩余字数:
< INPUT disabled maxLength = 4  name = remain size = 3 >
</ form >

 

-------------------------------------------------------------------------------------------------------------------------------

木木
2003 - 10 - 09 23 : 52
1 .oncontextmenu = " window.event.returnvalue=false "  将彻底屏蔽鼠标右键

< table border oncontextmenu = return ( false ) >< td > no </ table >  可用于Table

2 < body onselectstart = " return false " >  取消选取、防止复制

3onpaste
= " return false "  不准粘贴

4oncopy
= " 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.htmlcn.com/' " >

12取得控件的绝对位置

// 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+" left="+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 >

13光标是停在文本框文字的最后
< 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() " >

14最小化、最大化、关闭窗口
< 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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值