javascript進階編程運用

來源:互聯網
上載者:User

標籤:

一//各種尺寸 (size)

s += “\r\n網頁可見地區寬:“+ document.body.clientWidth;
s += “\r\n網頁可見地區高:“+ document.body.clientHeight;
s += “\r\n網頁可見地區高:“+ document.body.offsetWeight +” (包括邊線的寬)“;
s += “\r\n網頁可見地區高:“+ document.body.offsetHeight +” (包括邊線的寬)“;
s += “\r\n網頁本文全文寬:“+ document.body.scrollWidth;
s += “\r\n網頁本文全文高:“+ document.body.scrollHeight;
s += “\r\n網頁被捲去的高:“+ document.body.scrollTop;
s += “\r\n網頁被捲去的左:“+ document.body.scrollLeft;
s += “\r\n網頁本文部分上:“+ window.screenTop;
s += “\r\n網頁本文部分左:“+ window.screenLeft;
s += “\r\n螢幕解析度的高:“+ window.screen.height;
s += “\r\n螢幕解析度的寬:“+ window.screen.width;
s += “\r\n螢幕可用工作區高度:“+ window.screen.availHeight;
s += “\r\n螢幕可用工作區寬度:“+ window.screen.availWidth;
//過濾數字

 

//特殊用途







//不緩衝



//正則匹配

匹配中文字元的Regex: [\u4e00-\u9fa5]
匹配雙位元組字元(包括漢字在內):[\x00-\xff]
匹配空行的Regex:\n[\s| ]\r
匹配HTML標記的Regex:/<(.*)>.
<\ /\1>|<(.*) \ />/
匹配首尾空格的Regex:(\s)|(\s$)(像vbscript那樣的trim函數)
匹配Email地址的Regex:\w+([-+.]\w+)@\w+([-.]\w+).\w+([-.]\w+)
匹配網址URL的Regex:http://([\w-]+.)+[\w-]+(/[\w- ./?%&=]
)?
以下是例子:
利用Regex限制網頁表單裡的文字框輸入內容:
用Regex限制只能輸入中文:onkeyup=“value=value.replace(/[\u4E00-\u9FA5]/g,‘‘)” onbeforepaste=“clipboardData.setData(‘text‘,clipboardData.getData(‘text‘).replace(/[\u4E00-\u9FA5]/g,‘‘))”
1.用Regex限制只能輸入全形字元: onkeyup=“value=value.replace(/[\uFF00-\uFFFF]/g,‘‘)” onbeforepaste=“clipboardData.setData(‘text‘,clipboardData.getData(‘text‘).replace(/[\uFF00-\uFFFF]/g,‘‘))”
2.用Regex限制只能輸入數字:onkeyup=“value=value.replace(/[\d]/g,‘‘) “onbeforepaste=“clipboardData.setData(‘text‘,clipboardData.getData(‘text‘).replace(/[\d]/g,‘‘))”
3.用Regex限制只能輸入數字和英文:onkeyup=“value=value.replace(/[\W]/g,‘‘) “onbeforepaste=“clipboardData.setData(‘text‘,clipboardData.getData(‘text‘).replace(/[^\d]/g,‘‘))”

//消除映像工具列


or


//無提示關閉

function Close()
{
var ua=navigator.userAgent
var ie=navigator.appName==“Microsoft Internet Explorer”?true:false
if(ie)
{

   var IEversion=parseFloat(ua.substring(ua.indexOf("MSIE ")+5,ua.indexOf(";",ua.indexOf("MSIE ")))) 

if(IEversion< 5.5)
{

var str  = ‘<object id=noTipClose classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">‘     str += ‘<param name="Command" value="Close"></object>‘;     document.body.insertAdjacentHTML("beforeEnd", str);     document.all.noTipClose.Click(); 

}

   else 

{

    window.opener =null;     window.close();    } } 

else
{
window.close()

} 

}

//取得控制項得絕對位置(1)

 

//獲得控制項的絕對位置(2)

oRect = obj.getBoundingClientRect();
oRect.left
oRect.

//最小化,最大化,關閉






//游標停在文字最後

 

//頁面進入和退出的特效

進入頁面
推出頁面
這個是頁面被載入和調出時的一些特效。duration表示特效的期間,以秒為單位。transition表示使
用哪種特效,取值為1-23:
  0 矩形縮小
  1 矩形擴大
  2 圓形縮小
  3 圓形擴大
  4 下到上重新整理
  5 上到下重新整理
  6 左到右重新整理
  7 右到左重新整理
  8 豎百葉窗
  9 橫百葉窗
  10 錯位橫百葉窗
  11 錯位豎百葉窗
  12 點擴散
  13 左右到中間重新整理
  14 中間到左右重新整理
  15 中間到上下
  16 上下到中間
  17 右下到左上
  18 右上到左下
  19 左上到右下
  20 左下到右上
  21 橫條
  22 豎條
  23

//網頁是否被檢索
  其中屬性值有以下一些:
  屬性值為"all”: 檔案將被檢索,且頁上連結可被查詢;
  屬性值為"none”: 檔案不被檢索,而且不查詢頁上的連結;
  屬性值為"index”: 檔案將被檢索;
  屬性值為"follow”: 查詢頁上的連結;
  屬性值為"noindex”: 檔案不檢索,但可被查詢連結;
  屬性值為"nofollow”:

//列印分頁

page1

 

page2

//設定列印

classid=“clsid:1663ed61-23eb-11d2-b92f-008048fdd814”
codebase=“http://www.meadroid.com/scriptx/ScriptX.cab#Version=5,60,0,360”








具體使用手冊,更多資訊,點這裡

//內建的預覽列印
WebBrowser.ExecWB(1,1) 開啟
Web.ExecWB(2,1) 關閉現在所有的IE視窗,並開啟一個新視窗
Web.ExecWB(4,1) 儲存網頁
Web.ExecWB(6,1) 列印
Web.ExecWB(7,1) 預覽列印
Web.ExecWB(8,1) 列印版面設定
Web.ExecWB(10,1) 查看頁面屬性
Web.ExecWB(15,1) 好像是撤銷,有待確認
Web.ExecWB(17,1) 全選
Web.ExecWB(22,1) 重新整理
Web.ExecWB(45,1) 關閉表單無提示

 





 

 

 

 

//去掉列印時的頁首頁尾



//瀏覽器驗證

function checkBrowser()
{

this.ver=navigator.appVersion  this.dom=document.getElementById?1:0  this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0;  this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;  this.ie4=(document.all && !this.dom)?1:0;  this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;  this.ns4=(document.layers && !this.dom)?1:0;  this.mac=(this.ver.indexOf(‘Mac‘) > -1) ?1:0;  this.ope=(navigator.userAgent.indexOf(‘Opera‘)>-1);  this.ie=(this.ie6 || this.ie5 || this.ie4)  this.ns=(this.ns4 || this.ns5)  this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns5 || this.ns4 || this.mac || this.ope)  this.nbw=(!this.bw)  return this; 

}

//計算內容寬和高



sdf

//無模式的提示框 function modelessAlert(Msg)
{

window.showModelessDialog("javascript:alert(\""+escape(Msg)+"\");window.close();","","status:no;resizable:no;help:no;dialogHeight:height:30px;dialogHeight:40px;"); 

}

//屏蔽按鍵


屏蔽滑鼠右鍵、Ctrl+N、Shift+F10、Alt+F4、F11、F5重新整理、退格鍵



屏蔽滑鼠右鍵、Ctrl+N、Shift+F10、Alt+F4、F11、F5重新整理、退格鍵

//屏蔽列印

//移動的圖層,拖動

1.meizz

  1.  

    wlecome

     

//文檔狀態改變

 

//重新整理後不變的文字框







//訪問剪貼簿

event.dataTransfer.setData(“URL”, oImage.src);
sImageURL = event.dataTransfer.getData(“URL”)
(2)普通訪問
window.clipboardData.setData(“Text”,oSource.innerText);
window.clipboardData.getData(“Text”);

//操作COOKIE

function SetCookie(sName, sValue)
{
document.cookie = sName + “=” + escape(sValue) + “; “;
}
function GetCookie(sName)
{
var aCookie = document.cookie.split(“; “);
for (var i=0; i < aCookie.length; i++)
{

var aCrumb = aCookie.split(“=“);
if (sName == aCrumb[0])
return unescape(aCrumb[1]);
}

}
function DelCookie(sName)
{
document.cookie = sName + “=” + escape(sValue) + “; expires=Fri, 31 Dec 1999 23:59:59 GMT;“;
}

//setTimeout增加參數

 

//自訂的apply,call

Function.prototype.apply = function (obj, argu) {
if (obj) obj.constructor.prototype.caller = this;
var argus = new Array();
for (var i=0;i argus = “argu[” + i + “]“;
var r;
eval(“r = " + (obj ? (“obj.
caller(” + argus.join(“,“) + “);“) : (“this(” + argus.join(“,“) + “);“)));
return r;
};
Function.prototype.call = function (obj) {
var argu = new Array();
for (var i=1;i argu[i-1] = arguments;
return this.apply(obj, argu);
};

//下載檔案

function DownURL(strRemoteURL,strLocalURL)
{
try
{
var xmlHTTP=new ActiveXObject(“Microsoft.XMLHTTP”);
xmlHTTP.open(“Get”,strRemoteURL,false);
xmlHTTP.send();
var adodbStream=new ActiveXObject(“ADODB.Stream”);
adodbStream.Type=1;//1=adTypeBinary
adodbStream.Open();
adodbStream.write(xmlHTTP.responseBody);
adodbStream.SaveToFile(strLocalURL,2);
adodbStream.Close();
adodbStream=null;
xmlHTTP=null;

}
catch(e)
{
window.confirm(“下載URL出錯!“);
}
//window.confirm(“下載完成.“);
}

//檢驗串連是否有效

function getXML(URL)
{
var xmlhttp = new ActiveXObject(“microsoft.xmlhttp”);
xmlhttp.Open(“GET”,URL, false);
try
{
xmlhttp.Send();
}
catch(e){}
finally
{
var result = xmlhttp.responseText;
if(result)
{

if(xmlhttp.Status==200) {  return(true); } else  {  return(false); } 

}
else
{

return(false); 

}
}
}

//POST代替FORM

 

//readyState是xmlhttp返回資料的進度,0=載入中,1=未初始化,2=已載入,3=運行中,4=完成
end

javascript進階編程運用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.