Javaphua Blog

          BlogJava 首頁 新隨筆 聯(lián)系 聚合 管理
            46 Posts :: 5 Stories :: 46 Comments :: 0 Trackbacks

          常用鏈接

          留言簿(4)

          隨筆檔案

          文章檔案

          收藏夾

          Blog

          優(yōu)秀的技術(shù)站點

          技術(shù)鏈接

          資源站點

          搜索

          最新隨筆

          最新評論

          閱讀排行榜

          評論排行榜

          Javascript教程,javascript入門,學(xué)習(xí)筆記,Javascript Tutorials(源自網(wǎng)絡(luò))


          目 錄

          1.基本控件的使用
          2.讓TextArea自動換行
          3.讓TextArea支持Table鍵
          4.復(fù)制數(shù)據(jù)到剪貼板
          5.得到當(dāng)前選中的文本
          6.客戶端腳本的基本對象
          7.保護(hù)自己編寫的HTML和腳本的方法
          8.IE地址欄前換成自己的圖標(biāo)

          9.可以在收藏夾中顯示出你的圖標(biāo)
          10.關(guān)閉輸入法
          11.直接查看源代碼
          12.在Javascript中自定義一個對象(屬性,方法)
          13.取得控件的絕對位置
          14.光標(biāo)是停在文本框文字的最后
          15.判斷上一頁的來源
          16.最小化、最大化、關(guān)閉窗口
          17.檢查一段字符串是否全由數(shù)字組成
          18.獲得一個窗口的大小
          19.怎么判斷是否是字符
          20.檢測某個網(wǎng)站的鏈接速度
          21.各種樣式的光標(biāo)
          22.讓TEXTAREA自適應(yīng)文字的行數(shù)
          23.日期減去天數(shù)等于第二個日期
          24.選擇了哪一個Radio

          26.
          ENTER鍵可以讓光標(biāo)移到下一個輸入框
          28.引用其他網(wǎng)頁
          29.常用的正則表達(dá)式
          30.彈出來必須關(guān)閉才能繼續(xù)運行的提示對話框
          31.取得查詢字符串,然后就生成成對的數(shù)組
          32.另類的onload函數(shù)
          33.取得IE的版本
          34.提交表單 到不同地方
          35.判斷是否是整數(shù)
          36.鏈接css文件和js文件
          37.引用框架的內(nèi)容
          38.打開沒有最大化按鈕的窗口
          39.在頁面上顯示一個有邊框的Frame
          40.判斷日期1是不是大于日期2
          41.常用的Javascript內(nèi)建類的方法
          42.如何在另一個窗體對原來窗體進(jìn)行操作
          43.層的隱藏與顯示
          44.禁止右鍵
          45.得到當(dāng)前顯示器的分辨率
          46.定時運行特定代碼
          47.得到本頁網(wǎng)址
          48.保存當(dāng)前頁面的內(nèi)容
          49.用模式窗體,打開一個參數(shù)獲取窗體
          50.Web打印文檔

          ?1.基本控件的使用

           

          控件名 .value

          控件名 .value

          控件名 [i].checked??? .value?

          for each ob in 控件名
          ?? if ob.checked then
          ?? ???window.alert ob.value
          next

          控件名 .checked??? .value


          ?
          ??
          單行 ??????? ? 多行 ????? ??? 多選

          添加選項

          ExpList.add(new Option("New Option","3"));

          刪除選項

          ExpList.remove(ExpList.selectedIndex);

          設(shè)置當(dāng)前選項位置

          ExpList.selectedIndex=ExpList.length-1;

          循環(huán)整個選項
          并判斷是否被選擇

          for(i=0;i<ExpList.options.length;i++) {
          ? if(ExpList.options[i].selected){
          ???? //ExpList.options[i].text;
          ???? //ExpList.options[i].value;
          ? }
          }

          單個選項的值

          ExpList.options[i].text;
          ExpList.options[i].value;
          <span id="SomePlace1"></span>
          <div id="SomePlace1"></div>

          重新設(shè)計包含的 html

          SomePlace1.innerHTML=" 任意 html 字符串 "

          讓該空間的內(nèi)容消失

          SomePlace1.style.display="none";

          讓該空間的內(nèi)容顯示

          SomePlace1.style.display="block";

          鼠標(biāo)滑過出現(xiàn)提示 title="Help"

          <input type="hidden" name="MyValueName" value="123">

          控件名 .value
          跟隨事件Event(聲明方式特殊) <div id=hello1 style=position:absolute>太過分了!吃飯不叫我</div>
          <SCRIPT for=document EVENT=onmousemove>
          document_onmousemove();
          function document_onmousemove() {
          ? hello1.style.left=event.x+10;
          ? hello1.style.top=event.y+10;
          }
          </SCRIPT>


          <返回>

          2.讓TextArea自動換行

          ? 使用TextArea的Wrap屬性

          • Wrap may be set to one of the following values:

            • OFF - Default, lines are not wrapped.

            • PHYSICAL - Wrap lines and place new line characters where the line wraps.

            • VIRTUAL - Wrap lines on the screen, but receive them as one line.

          ASP中手動換行用: replace(rs("A"),"</br>", VBCRLF)
          str=request.querystring("text1")
          str=Replace(str, Chr(32), " ")
          '把空格換成 標(biāo)志
          str=Replace(str, vbCrLf, "<br>")
          '把回車換行符換成<br>標(biāo)志
          調(diào)出時再轉(zhuǎn)過來就好了

          <返回>

          3.讓TextArea支持Table鍵
          <SCRIPT LANGUAGE="JavaScript">
          <!--
          function testTab()
          {
          ?? var sel = document.selection.createRange();
          ?? var mytext= sel.text;
          ?? var i,j,k;
          ?? if (event.shiftKey && event.keyCode == 9)
          ?? {
          ????? arr=mytext.split(String.fromCharCode(13,10))
          ????? mytext=""

          ????? for(k=0;k<arr.length;k++)
          ????? {
          ???????? for (j=1; j<=4;j++)
          ???????? {
          ??????????? if(arr[k].substr(0,1)=="\u0020")
          ??????????? {
          ?????????????? arr[k]=arr[k].slice(1)
          ??????????? }
          ???????? }
          ???????? mytext += arr[k] + ((k==(arr.length-1))? "" : String.fromCharCode(13,10));
          ????? }
          ????? with(sel){
          ???????? sel.text = mytext;
          ???????? collapse(true)
          ???????? moveEnd("character",0)
          ???????? moveStart("character",(mytext.length ) * -1)
          ???????? select()
          ????? }

          ????? window.event.cancelBubble = true;
          ????? event.returnValue = false;
          ????? return;
          ?? }
          ?? if (event.keyCode == 9)
          ?? {
          ????? arr=mytext.split(String.fromCharCode(13,10))
          ????? mytext=""
          ????? for(j=0;j<arr.length;j++)
          ????? {
          ???????? mytext += "\u0020\u0020\u0020\u0020" + arr[j] + ((j==(arr.length-1))? "" : String.fromCharCode(13,10));
          ????? }
          ????? with(sel){
          ???????? sel.text = mytext;
          ???????? collapse(true)
          ???????? moveEnd("character",0)
          ???????? moveStart("character",(mytext.length -4) * -1)
          ???????? select()
          ????? }

          ????? window.event.cancelBubble = true;
          ????? event.returnValue = false;
          ????? return;
          ?? }
          }
          //-->
          </SCRIPT>

          <返回>

          4.復(fù)制數(shù)據(jù)到剪貼板

          ?JM_cc(txt)

          ?window.clipboardData.setData("Text", txt);
          ?global.focus();
          ?document.execCommand('Paste');
          ?window.clipboardData.setData("Text", old);

          <返回>

          5.得到當(dāng)前選中的文本


          var sel = document.selection.createRange();
          var mytext= sel.text;? //當(dāng)前選中的文本


          var e = event.srcElement;? //設(shè)置文本為選中
          var r =e.createTextRange();
          r.moveStart('character',e.value.length);
          r.collapse(true);
          r.select();

          <返回>

          6.客戶端腳本的基本對象
           


          <返回>

          7.保護(hù)自己編寫的HTML和腳本的方法
          ? (1). oncontextmenu="window.event.returnValue=false" 將徹底屏蔽鼠標(biāo)右鍵
          ??? <table border oncontextmenu=return(false)><td>no</table> 可用于Table
          ? (2). <body onselectstart="return false"> 取消選取、防止復(fù)制
          ? (3). onpaste="return false" 不準(zhǔn)粘貼
          ? (4). oncopy="return false;" oncut="return false;" 防止復(fù)制
          ? (5). 防止被人frame
          ????? <SCRIPT LANGUAGE=JAVASCRIPT><!--
          ???????? if (top.location != self.location)top.location=self.location;
          ?????? // -->
          ????? </SCRIPT>
          ? (6). 永遠(yuǎn)都會帶著框架
          ???? <script language="JavaScript"><!--
          ??????? if (window == top)top.location.href = "frames.htm"; //frames.htm為框架網(wǎng)頁
          ???? // --></script>
          ? (7).網(wǎng)頁將不能被另存為
          ???? <noscript><iframe src=*.html></iframe></noscript>

          <返回>

          8.IE地址欄前換成自己的圖標(biāo)
          ?<link rel="Shortcut Icon" href="favicon.ico">

          <返回>

          9.可以在收藏夾中顯示出你的圖標(biāo)

          ?<link rel="Bookmark" href="favicon.ico">

          <返回>

          10.關(guān)閉輸入法

          ?<input style="ime-mode:disabled">

          <返回>

          11.直接查看源代碼
          ?
          ?<input type=button value=查看網(wǎng)頁源代碼 onclick="window.location = 'view-source:'+ 'http://www.csdn.net/'">

          <返回>

          12.在Javascript中定義一個對象(屬性,方法)

          function pasta(grain, width, hasEgg) {
          ??? this.grain = grain;
          ??? this.width = width;
          ??? this.hasEgg = hasEgg;
          ??? this.toString = pastaToString;
          }

          function pastaToString() {
          ??? return "Grain: " + this.grain + "\n" + "Width: " + this.width + "\n" + "Egg?: " + Boolean(this.hasEgg);
          }

          var P1=new pasta(3,3,false);

          <返回>

          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>

          <返回>

          14. 光標(biāo)是停在文本框文字的最后

          <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. 最小化、最大化、關(guān)閉窗口

          <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=關(guān)閉 onclick=hh3.Click()>
          本例適用于IE

          <返回>

          17. 檢查一段字符串是否全由數(shù)字組成

          <script language="Javascript"><!--
          function checkNum(str){return str.match(/\D/)==null}
          // --></script>

          <返回>

          18. 獲得一個窗口的大小

          document.body.clientWidth,document.body.clientHeight

          <返回>

          19. 怎么判斷是否是字符

          if (/[^\x00-\xff]/g.test(s))
          ? alert("含有漢字");
          else
          ? alert("全是字符");

          <返回>

          20. 檢測某個網(wǎng)站的鏈接速度

          把如下代碼加入<body>區(qū)域中:
          <script language=Javascript>
          tim=1
          setInterval("tim++",100)
          b=1

          var autourl=new Array()
          autourl[1]="www.njcatv.net"
          autourl[2]="javacool.3322.net"
          autourl[3]="www.sina.com.cn"
          autourl[4]="www.nuaa.edu.cn"
          autourl[5]="www.cctv.com"

          function butt(){
          ?? document.write("<form name=autof>")
          ?? for(var i=1;i<autourl.length;i++)
          ????? document.write("<input type=text name=txt"+i+" size=10 value=測試中……> =》<input type=text name=url"+i+" size=40> =》<input type=button value=GO onclick=window.open(this.form.url"+i+".value)><br/>")
          ?? document.write("<input type=submit value=刷新></form>")
          }
          butt()
          function auto(url){
          ?? document.forms[0]["url"+b].value=url
          ?? if(tim>200)
          ?? {
          ????? document.forms[0]["txt"+b].value="鏈接超時"
          ?? }
          ?? else
          ?? {
          ????? document.forms[0]["txt"+b].value="時間"+tim/10+"秒"
          ?? }
          ?? b++
          }
          function run()
          {
          ?? for(var i=1;i<autourl.length;i++)
          ????? document.write("<img src=http://"+autourl[i]+"/"+Math.random()+" width=1 height=1 onerror=auto('http://"+autourl[i]+"')>")
          }
          run()</script>

          <返回>

          21. 各種樣式的光標(biāo)

          auto :標(biāo)準(zhǔn)光標(biāo)
          default :標(biāo)準(zhǔn)箭頭
          hand :手形光標(biāo)
          wait :等待光標(biāo)
          text :I形光標(biāo)
          vertical-text :水平I形光標(biāo)
          no-drop :不可拖動光標(biāo)
          not-allowed :無效光標(biāo)
          help :?幫助光標(biāo)
          all-scroll :三角方向標(biāo)
          move :移動標(biāo)
          crosshair :十字標(biāo)
          e-resize
          n-resize
          nw-resize
          w-resize
          s-resize
          se-resize
          sw-resize

          <返回>

          22.讓TEXTAREA自適應(yīng)文字的行數(shù)

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

          <返回>

          23. 日期減去天數(shù)等于第二個日期
          <script language=Javascript>
          function cc(dd,dadd)
          {
          //可以加上錯誤處理
          ?? var a = new Date(dd)
          ?? a = a.valueOf()
          ?? a = a - dadd * 24 * 60 * 60 * 1000
          ?? a = new Date(a)
          ?? alert(a.getFullYear() + "年" + (a.getMonth() + 1) + "月" + a.getDate() + "日")
          }
          cc("12/23/2002",2)
          </script>

          <返回>

          24. 選擇了哪一個Radio

          <HTML>
          <script language="vbscript">
          function checkme()
          ?? for each ob in radio1
          ?? if ob.checked then
          ????? window.alert ob.value
          ?? next
          end function
          </script>
          <BODY>
          <INPUT name="radio1" type="radio" value="style" checked>Style
          <INPUT name="radio1" type="radio" value="barcode">Barcode
          <INPUT type="button" value="check" onclick="checkme()">
          </BODY></HTML>

          <返回>

          25.獲得本頁url的request.servervariables("")集合

          Response.Write "<TABLE border=1><!-- Table Header --><TR><TD><B>Variables</B></TD><TD><B>Value</B></TD></TR>"
          for each ob in Request.ServerVariables
          ?? Response.Write "<TR><TD>"&ob&"</TD><TD>"&Request.ServerVariables(ob)&"</TD></TR>"
          next
          Response.Write "</TABLE>"

          <返回>

          26.ENTER鍵可以讓光標(biāo)移到下一個輸入框

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

          <返回>

          28.引用其他網(wǎng)頁

          <table width=100% border="0"><tr><td><script language="JavaScript" location="http://91down.7161.net" id="nd91down" src="http://91down.7161.net/js/new1-1.htm"></script></td><td><script language="JavaScript" location="http://91down.7161.net" id="nd91down" src="http://91down.7161.net/js/new1-2.htm"></script></td></tr></table>

          <返回>

          29.常用的正則表達(dá)式

          匹配中文字符的正則表達(dá)式: [\u4e00-\u9fa5]
          匹配雙字節(jié)字符(包括漢字在內(nèi)):[^\x00-\xff]
          匹配空行的正則表達(dá)式:\n[\s| ]*\r
          匹配HTML標(biāo)記的正則表達(dá)式:/<(.*)>.*<\/\1>|<(.*) \/>/
          匹配首尾空格的正則表達(dá)式:(^\s*)|(\s*$)
          匹配Email地址的正則表達(dá)式:\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
          匹配網(wǎng)址URL的正則表達(dá)式:http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?

          (1)應(yīng)用:計算字符串的長度(一個雙字節(jié)字符長度計2,ASCII字符計1)
          ????????
          ??? String.prototype.len=function(){return this.replace([^\x00-\xff]/g,"aa").length;}

          (2)應(yīng)用:javascript中沒有像vbscript那樣的trim函數(shù),我們就可以利用這個表達(dá)式來實現(xiàn)
          ?? String.prototype.trim = function()
          ?? {
          ????? return this.replace(/(^\s*)|(\s*$)/g, "");
          ?? }
          (3)應(yīng)用:利用正則表達(dá)式分解和轉(zhuǎn)換IP地址
          ?? function IP2V(ip) //IP地址轉(zhuǎn)換成對應(yīng)數(shù)值
          ?? {
          ????? re=/(\d+)\.(\d+)\.(\d+)\.(\d+)/g //匹配IP地址的正則表達(dá)式
          ????? if(re.test(ip))
          ????? {
          ???????? return RegExp.$1*Math.pow(255,3))+RegExp.$2*Math.pow(255,2))+RegExp.$3*255+RegExp.$4*1
          ????? }
          ????? else
          ????? {
          ???????? throw new Error("Not a valid IP address!")
          ????? }
          ?? }
          (4)應(yīng)用:從URL地址中提取文件名的javascript程序
          ?? s="http://www.9499.net/page1.htm";
          ?? s=s.replace(/(.*\/){0,}([^\.]+).*/ig,"$2") ; //Page1.htm
          (5)應(yīng)用:利用正則表達(dá)式限制網(wǎng)頁表單里的文本框輸入內(nèi)容
          ?? 用正則表達(dá)式限制只能輸入中文:onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))"
          ?? 用正則表達(dá)式限制只能輸入全角字符: onkeyup="value=value.replace(/[^\uFF00-\uFFFF]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\uFF00-\uFFFF]/g,''))"
          ?? 用正則表達(dá)式限制只能輸入數(shù)字:onkeyup="value=value.replace(/[^\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"
          ?? 用正則表達(dá)式限制只能輸入數(shù)字和英文:onkeyup="value=value.replace(/[\W]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"

          <返回>

          30.彈出來提示對話框
          window.showModalDialog(url);

          <返回>

          31.取得查詢字符串,然后就生成成對的數(shù)組
          var argstr = window.top.location.search.substring(1,window.top.location.search.length);
          var args = argstr.split('&');

          <返回>

          32.另類的onload函數(shù)
          <SCRIPT FOR=window event=onload>
          try
          {
          ? Start();
          }
          catch (exception)
          {
          }
          </script>

          <返回>

          33.取得IE的版本
          var ieVer = parseFloat(navigator.appVersion.substring(navigator.appVersion.indexOf("MSIE ")+5, navigator.appVersion.length))
          var isIE6 = ieVer >= 6.0

          <返回>

          34.提交表單
          // aimForm 為表單名??? aimPage為提交到的頁

          //提交表單到新建的網(wǎng)頁
          function SubmitFormToNewPage(aimForm,aimPage){
          ?? aimForm.method="POST";
          ?? aimForm.target="_blank";
          ?? aimForm.action=aimPage;
          ?? aimForm.submit();
          }

          //在本地提交表單
          function SubmitFormToLocalPage(aimForm,aimPage){
          ?? aimForm.method="POST";
          ?? aimForm.target="_self";
          ?? aimForm.action=aimPage;
          ?? aimForm.submit();
          }


          <返回>

          35.判斷是否是整數(shù)
          function IsNum(s)? //整數(shù)
          {
          ?? if(s=="null"||s=="undefined"||s.length<1)
          ????? return false;
          ?? if(isNaN(parseInt(s)))
          ????? return false;
          ?? else
          ?? if((parseInt(s)+"").length!=s.length)
          ????? return false;
          ?? else
          ????? return true;
          }

          function IsNumber(JudgeNum){? //判斷大于0的數(shù)
          ?? var JudgeStr=JudgeNum.toString();
          ?? for (var i=0;i<JudgeStr.length;i++) {
          ????? var oneChar=JudgeStr.charAt(i);

          ????? if (oneChar<"0" || oneChar >"9"){
          ???????? return false;
          ????? }
          ?? }
          ?? return true;
          }

          <返回>

          36.鏈接css文件和js文件
          <link rel="stylesheet" href="../css/style.css" type="text/css">
          <script language="javascript" src="../includes/jslib.js" ></script>

          <返回>

          37.引用框架的內(nèi)容
          window.top.frames["mainFrame"].location.href=s;
          在IFRAME標(biāo)簽中引用框架的內(nèi)容
          parent.frames["mainFrame"].location.href
          在窗口中引用IFrame中的內(nèi)容
          window.top.frames["mainFrame"].confFrame.location.href

          <返回>

          38.打開沒有最大化按鈕的窗口
          window.open("http://www.google.com","","width=250,height=220,scrollbars=no,resizable=no,center=yes");

          <返回>

          39.在頁面上顯示一個有邊框的Frame
          <fieldset style="width:500;height:100">
          <legend>標(biāo)題</legend>
          具體內(nèi)容
          </fieldset>

          <返回>

          40.判斷日期1是不是大于日期2

          function IsDate1AfterThanDate2(year1,month1,day1,year2,month2,day2){
          ?? var iFrom=Date.parse(month1+"-"+day1+"-"+year1);
          ?? var iTo=Date.parse(month2+"-"+day2+"-"+year2);
          ?? if(iFrom>iTo)
          ????? return true;
          ?? else
          ????? return false;
          }

          function IsDate(year,month,day){
          ?? if( (!IsNumber(year))||(year.length!=4))
          ????? return false;
          ?? if( (!IsNumber(month))||(month>12)||(month<1) )
          ????? return false;
          ?? if( (!IsNumber(day))||(day>31)||(day<1) )
          ????? return false;

          ?? var myDate=new Date();
          ????? myDate.setFullYear(year,month-1,day);
          ?? if (isNaN(myDate.getFullYear())){
          ????? return false;
          ?? }
          ?? else{
          ????? if( (myDate.getFullYear()!=year)||(myDate.getDate()!=day)||(myDate.getMonth()!=(month-1).toString()) )
          ???????? return false;
          ?? }
          ????? return true;
          }

          function IsNumber(JudgeNum){
          ?? var JudgeStr=JudgeNum.toString();
          ?? for (var i=0;i<JudgeStr.length;i++) {
          ????? var oneChar=JudgeStr.charAt(i);

          ????? if (oneChar<"0" || oneChar >"9"){
          ???????? return false;
          ????? }
          ?? }
          ?? return true;
          }

          <返回>

          41.常用的Javascript內(nèi)建類的方法
           

          對象

          方法或?qū)傩?/span>

          意義

          例子

          Array

          length

          表示數(shù)組大小,也可以通過該屬性動態(tài)調(diào)整數(shù)組大小。設(shè)置可以不調(diào)整它直接擴(kuò)大數(shù)組。

          var theMonths = new Array(12);
          theMonths[0] = "Jan";
          theMonths[1] = "Feb";
          theMonths[2] = "Mar";
          theMonths[20] = "12";

          concat

          把兩個數(shù)組合并

          a = new Array(1,2,3);
          b = new Array(4,5,6);
          a = a. concat(b)

          join

          把數(shù)組變?yōu)樽址?/span>

          ?? a = new Array(0,1,2,3,4);
          ?? b = a.join("-");

          Date

          Date.parse(dateVal)

          將日期轉(zhuǎn)為數(shù)字,用于比較兩個日期的大小。 dateVal 格式為 month+day+year

          iFrom=Date.parse(“10-1-2004”);

          setFullYear (year,month-1,day)

          用于判斷 3 個字符串合起來是不是日期或者判斷該天是不是存在。這里 month 0 開始,故和實際值差 1

          myDate.setFullYear(year,month-1,day);
          if (isNaN(myDate.getFullYear())){
          ????? return false;
          }
          else{
          ? if( (myDate.getFullYear()!=year)||
          ????? (myDate.getDate()!=day)||
          ????? (myDate.getMonth()!=(month-1) )
          ????? return false;?
          }

          Date()

          獲得當(dāng)前時間

          d = new Date();??????????????????????????

          Global (全局類,引用方法可以不要帶 Global.

          isNaN

          當(dāng)從字符到日期轉(zhuǎn)換失敗,或者從字符到數(shù)字轉(zhuǎn)換失敗,都返回 NaN 。用 isNaN 可以判斷返回值是不是 NaN

          ?

          parseInt

          將字符串轉(zhuǎn)換為整數(shù),轉(zhuǎn)換失敗返回 NaN 或者盡量轉(zhuǎn)換。所以用它來判斷是不是數(shù)字,還要加上判斷轉(zhuǎn)化后長度是不是一樣

          parseInt("abc")???? // 返回 NaN
          parseInt("12abc")?? //
          返回 12
          parseInt("12")?? //
          返回 12

          parseFloat

          轉(zhuǎn)為實數(shù)

          ?

          String

          主要函數(shù)和 Java 或者 C #一樣

          replace

          替代某個字符。如果僅替代一個和 C #一樣,如果要替代全部某字符,就得用到了匹配串

          ? re=/#/g;
          ? str=str.replace(re,"<br>");

          ? 把#用
          <br> 代替

          split

          將某個字符串按指定間隔符分割

          var s = "The rain in Spain";
          ss = s.split(" ");? //ss
          是一個數(shù)組

          <返回>

          42.如何在另一個窗體 對原來窗體進(jìn)行操作

          ? 在打開的新窗體,用window.opener來訪問原來窗體的對象。例如? alert(window.opener.hiddens.value);
          ? 可以對層進(jìn)行重寫Html代碼,例如 window.opener.divStatus.innerHTML="Proctored";
          ?
          <返回>

          43.層的隱藏與顯示


          ?? 只要設(shè)置層的style的display屬性即可。 比如<div style="display:none" id="divTest">隱藏的層</div>
          ?? 如果要顯示它可以通過腳本來控制。例如divTest.style.display = "";? 或者? window.document.getElementById("MyDiv").style.display = "";

          <返回>

          44.禁止右鍵

          <body oncontextmenu="return false">

          <返回>

          45.得到當(dāng)前顯示器的分辨率

          window.srceen.width 得到屏幕的寬度
          window.srceen.height 得到屏幕的高度

          <返回>

          46.定時運行特定代碼


          setTimeout(Code,Timeout);?? 是從現(xiàn)在算起多少微秒后運行該代碼(只運行一次)
          setInterval(Code,Timeout);? 是每隔多少微秒運行一次代碼
          Code是一段字符串,里邊是js代碼,Timeout是時間間隔,單位是微秒

          <input name="txtTimer" value="10秒">
          <SCRIPT LANGUAGE=javascript>
          <!--
          ??? waitTime=10000; //10 秒
          ??? timer=setInterval("OnTimer()",1000);

          ??? function OnTimer(){
          ??????? waitTime=waitTime-1000;
          ??????? if(waitTime==0){
          ??????????? window.close();
          ??????? }
          ??????? txtTimer.value=waitTime/1000+"秒";
          ??? }
          //-->
          </SCRIPT>

          <返回>

          47.得到本頁網(wǎng)址

          var Url = window.location.href;

          <返回>

          48.保存當(dāng)前頁面的內(nèi)容

          document.execCommand("SaveAs","","C:\\index.htm");

          <返回>

          49.用模式窗體,打開一個參數(shù)獲取窗體

          主窗體中用
          ?? var returnvalue=window.showModalDialog('../webPri/GetDate.asp',frmApplyPriItem,"status=no; help=no; dialogWidth=320px; dialogHeight=120px;");

          子窗體中用
          ?? window.returnValue="OK";
          ?? window.dialogArguments.FormObject.value

          <返回>


          50.Web打印文檔

          <!--語言無關(guān) 保存成 .HTML-->
          <html>
          <head>
          <meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
          <title>網(wǎng)絡(luò)打印模板頁</title>
          <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
          <!--media=print 這個屬性可以在打印時有效-->
          <style media=print>
          .Noprint{display:none;}
          .PageNext{page-break-after: always;}
          </style>

          <style>
          .tdp
          {
          border-bottom: 1 solid #000000;
          border-left: 1 solid #000000;
          border-right: 0 solid #ffffff;
          border-top: 0 solid #ffffff;
          }
          .tabp
          {
          border-color: #000000 #000000 #000000 #000000;
          border-style: solid;
          border-top-width: 2px;
          border-right-width: 2px;
          border-bottom-width: 1px;
          border-left-width: 1px;
          }
          .NOPRINT {
          font-family: "宋體";
          font-size: 9pt;
          }
          </style>

          </head>

          <body >
          <center class="Noprint" >
          <p>
          <OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0>
          </OBJECT>
          <input type=button value=打印 onclick=document.all.WebBrowser.ExecWB(6,1)>
          <input type=button value=直接打印 onclick=document.all.WebBrowser.ExecWB(6,6)>
          <input type=button value=頁面設(shè)置 onclick=document.all.WebBrowser.ExecWB(8,1)>
          </p>
          <p> <input type=button value=打印預(yù)覽 onclick=document.all.WebBrowser.ExecWB(7,1)>
          <br/>
          </p>
          <hr align="center" width="90%" size="1" noshade>
          </center>

          <table width="90%" border="0" align="center" cellpadding="2" cellspacing="0" class="tabp">
          <tr>
          <td colspan="3" class="tdp">第1頁</td>
          </tr>
          <tr>
          <td width="29%" class="tdp"> </td>
          <td width="28%" class="tdp"> </td>
          <td width="43%" class="tdp"> </td>
          </tr>
          <tr>
          <td colspan="3" class="tdp"> </td>
          </tr>
          <tr>
          <td colspan="3" class="tdp"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
          <td width="50%" class="tdp"><p>這樣的報表</p>
          <p>對一般的要求就夠了。</p></td>
          <td> </td>
          </tr>
          </table></td>
          </tr>
          </table>
          <hr align="center" width="90%" size="1" noshade class="NOPRINT" >
          <!--分頁-->
          <div class="PageNext"></div>
          <table width="90%" border="0" align="center" cellpadding="2" cellspacing="0" class="tabp">
          <tr>
          <td class="tdp">第2頁</td>
          </tr>
          <tr>
          <td class="tdp">看到分頁了吧</td>
          </tr>
          <tr>
          <td class="tdp"> </td>
          </tr>
          <tr>
          <td class="tdp"> </td>
          </tr>
          <tr>
          <td class="tdp"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
          <td width="50%" class="tdp"><p>這樣的報表</p>
          <p>對一般的要求就夠了。</p></td>
          <td> </td>
          </tr>
          </table></td>
          </tr>
          </table>
          </body>
          </html>


          在基于框架的網(wǎng)頁打印時,用如下函數(shù)可以打印某個框架內(nèi)的網(wǎng)頁
          <input type=button onclick="printweb(this)">
          <script>
          function printweb()
          {
          ?? this.focus();
          ?? window.print();
          }
          </script>

          posted on 2006-07-25 13:57 Javaphua 閱讀(554) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 沈丘县| 尚志市| 阿坝| 永靖县| 志丹县| 登封市| 成安县| 宁远县| 山丹县| 沭阳县| 沁阳市| 乐都县| 凉城县| 嘉祥县| 阿克| 哈巴河县| 九龙坡区| 南木林县| 治多县| 临洮县| 阿克陶县| 沙雅县| 湄潭县| 永新县| 东乌珠穆沁旗| 巧家县| 吉水县| 文安县| 黎平县| 石台县| 谢通门县| 邵武市| 阿坝县| 桃江县| 丰原市| 方正县| 宜昌市| 湛江市| 泾源县| 历史| 龙岩市|