本文目錄一覽:
js中的常用函數
下面介紹全頁面刷新方法:有時候可能會用到
window.location.reload()刷新當前頁面.
parent.location.reload()刷新父親對象(用於框架)
opener.location.reload()刷新父窗口對象(用於單開窗口)
top.location.reload()刷新最頂端對象(用於多開窗口)
下面再介紹一些javascript基本函數
1.document.write(」”);為 輸出語句
2.js中的注釋為//
3.傳統的html文檔順序是:document-html-(head,body)
4.一個瀏覽器窗口中的dom順序是:window-(navigator,screen,history,location,document)
5.得到表單中元素的名稱和值:document.getelementbyid(」表單中元素的id號」).name(或value)
6.一個小寫轉大寫的js: document.getelementbyid(」output」).value = document.getelementbyid (」input」).value.touppercase();
7.js中的值類型:string,number,boolean,null,object,function
8.js中的字元型轉換成數值型:parseint(),parsefloat()
9.js中的數字轉換成字元型:(」”+變數)
10.js中的取字元串長度是:(length)
11.js中的字元與字元相連接使用+號.
12.js中的比較操作符有:==等於,!=不等於,,=,.=
13.js中聲明變數使用:var來進行聲明
14.js中的判斷語句結構:if(condition){}else{}
15.js中的循環結構:for([initial expression];[condition];[upadte expression]) {inside loop}
16.循環中止的命令是:break
17.js中的函數定義:function functionname([parameter],…){statement[s]}
18.當文件中出現多個form表單時.可以用document.forms[0],document.forms[1]來代替.
19.窗口:打開窗口window.open(), 關閉一個窗口:window.close(), 窗口本身:self
20.狀態欄的設置:window.status=」字元」;
21.彈出提示信息:window.alert(」字元」);
22.彈出確認框:window.confirm();
23.彈出輸入提示框:window.prompt();
24.指定當前顯示鏈接的位置:window.location.href=」url」
25.取出窗體中的所有表單的數量:document.forms.length
26.關閉文檔的輸出流:document.close();
27.字元串追加連接符:+=
28.創建一個文檔元素:document.createelement(),document.createtextnode()
29.得到元素的方法:document.getelementbyid()
49.引用一個文件式的js:
50.指定在不支持腳本的瀏覽器顯示的html:
51.當超鏈和onclick事件都有時,則老版本的瀏覽器轉向a.html,否則轉向b.html.例: dfsadf
52.js 的內建對象 有:array,boolean,date,error,evalerror,function,math,number,object,rangeerror,referenceerror,regexp,string,syntaxerror,typeerror,urierror
53.js中的換行:/n
54.窗口全屏大小:function fullscreen(){ this.moveto(0,0);this.outerwidth=screen.availwidth;this.outerheight=screen.availheight;}window.maximize=fullscreen;
55.js中的all代表其下層的全部元素
56.js中的焦點順序:document.getelementbyid(」表單元素」).tabindex = 1
57.innerhtml的值是表單元素的值:如how are you,則innerhtml的值就是:how are you
58.innertext的值和上面的一樣,只不過不會把em這種標記顯示出來.
59.contenteditable可設置元素是否可被修改,iscontenteditable返回是否可修改的狀態.
60.isdisabled判斷是否為禁止狀態.disabled設置禁止狀態
61.length取得長度,返回整型數值
62.addbehavior()是一種js調用的外部函數文件其擴展名為.htc
63.window.focus()使當前的窗口在所有窗口之前.
64.blur()指失去焦點.與focus()相反.
65.select()指元素為選中狀態.
66.防止用戶對文本框中輸入文本:onfocus=」this.blur()」
67.取出該元素在頁面中出現的數量:document.all.tags(」div(或其它html標記符)」).length
68.js中分為兩種窗體輸出:模態和非模態.window.showmodaldialog(),window.showmodeless()
69.狀態欄文字的設置:window.status=『文字』,默認的狀態欄文字設置:window.defaultstatus = 『文字.』;
70.添加到收藏夾:external.addfavorite(」」,」google」);
71.js中遇到腳本錯誤時不做任何操作:window.onerror = donothing; 指定錯誤句柄的語法為:window.onerror = handleerror;
72.js中指定當前打開窗口的父窗口:window.opener,支持opener.opener…的多重繼續.
73.js中的self指的是當前的窗口
74.js中狀態欄顯示內容:window.status=」內容」
75.js中的top指的是框架集中最頂層的框架
76.js中關閉當前的窗口:window.close();
77.js中提出是否確認的框:if(confirm(」are you sure?」)){alert(」ok」);}else{alert(」not ok」);}
78.js中的窗口重定向:window.navigate(」」);
79.js中的列印:window.print()
80.js中的提示輸入框:window.prompt(」message」,」defaultreply」);
81.js中的窗口滾動條:window.scroll(x,y)
82.js中的窗口滾動到位置:window.scrollby
83.js中設置時間間隔:setinterval(」expr」,msecdelay)或setinterval(funcref,msecdelay)或settimeout
84.js中的模態顯示在ie4+行,在nn中不行:showmodaldialog(」url」[,arguments][,features]);
85.js中的退出之前使用的句柄:function verifyclose(){event.returnvalue=」we really like you and hope you will stay longer.」;}} window.onbeforeunload=verifyclose;
86.當窗體第一次調用時使用的文件句柄:onload()
87.當窗體關閉時調用的文件句柄:onunload()
88.window.location的屬性: protocol(http:),hostname(),port(80),host(),pathname(」/a/a.html」),hash(」#giantgizmo」,指跳轉到相應的錨記),href(全部的信息)
89.window.location.reload()刷新當前頁面.
89-1.parent.location.reload()刷新父親對象(用於框架)
89-2.opener.location.reload()刷新父窗口對象(用於單開窗口)
89-3.top.location.reload()刷新最頂端對象(用於多開窗口)
90.window.history.back()返回上一頁,window.history.forward()返回下一頁,window.history.go(返回第幾頁,也可以使用訪問過的url)
91.document.write()不換行的輸出,document.writeln()換行輸出
92.document.body.nowrap=true;防止鏈接文字折行.
93.變數名.charat(第幾位),取該變數的第幾位的字元.
94.」abc」.charcodeat(第幾個),返回第幾個字元的ascii碼值.
95.字元串連接:string.concat(string2),或用+=進行連接
96.變數.indexof(」字元」,起始位置),返回第一個出現的位置(從0開始計算)
97.string.lastindexof(searchstring[,startindex])最後一次出現的位置.
98.string.match(regexpression),判斷字元是否匹配.
99.string.replace(regexpression,replacestring)替換現有字元串.
100.string.split(分隔符)返回一個數組存儲值.
101.string.substr(start[,length])取從第幾位到指定長度的字元串.
102.string.tolowercase()使字元串全部變為小寫.
103.string.touppercase()使全部字元變為大寫.
104.parseint(string[,radix(代表進位)])強制轉換成整型.
105.parsefloat(string[,radix])強制轉換成浮點型.
106.isnan(變數):測試是否為數值型.
107.定義常量的關鍵字:const,定義變數的關鍵字:var
com組件如何非同步調用js函數?
//初始化創建線程 STDMETHODIMP CJSCallBack::Initialize(void) { // TODO: 在此添加實現代碼 DWORD dThreadId; m_hThreadHandle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)CallJspFunctionThread, this, 0, dThreadId); return S_OK; } //線程函數 UINT CJSCallBack::CallJspFunctionThread(LPVOID param) { CJSCallBack* pCallBack = (CJSCallBack*)param; while(m_bRunThread) { while(m_bCallJspFunc) { pCallBack-CallJsFunction(); m_bCallJspFunc = FALSE; } Sleep(1); } return 0; } //設置回調函數 STDMETHODIMP CJSCallBack::SetJsCallbackFunc(VARIANT scriptCallback) { // TODO: 在此添加實現代碼 if (scriptCallback.vt == VT_DISPATCH) { m_spCallback = scriptCallback.pdispVal; } return S_OK; } //調用回調函數 void CJSCallBack::CallJsFunction() { CComVariant avarParams[1]; avarParams[0] = m_szDisplay; //指定回調函數的參數 DISPPARAMS params = { avarParams, NULL, 1, 0 }; if(m_spCallback) { HRESULT hr = m_spCallback-Invoke(0, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, params, NULL, NULL, NULL); } } //觸發調用回調函數 STDMETHODIMP CJSCallBack::Print(BSTR bstrToPrint, LONG lWait) { // TODO: 在此添加實現代碼 _bstr_t bsPrint = bstrToPrint; char* szPrint = bsPrint; Sleep(500); m_szDisplay = “Succeed to Print”; HRESULT hr = CallPrintFunction(szPrint); if ( FAILED(hr) ) { m_szDisplay = “Failed to Print”; } switch (lWait) { case 0: CallJsFunction(); break; case 1: { m_bCallJspFunc = TRUE; Sleep(30); } break; default: break; } return S_OK; }function TestCallBack() { var obj = new ActiveXObject(“CallBackForJs.JSCallBack.1”); var result = obj.Initialize(); result = obj.SetJsCallbackFunc(printMsg); obj.Print(“abc”,1); obj.UnInitialize(); } function printMsg(msg) { alert(msg); }
JS調用COM組件是什麼意思
在js下面直接將function傳給這個屬性,com組件裡面調用這個IDispatch的函數即可。
idl文件,注意onevent1這裡。
[plain] view plain copy
import “oaidl.idl”;
import “ocidl.idl”;
[
object,
uuid(6A6140E8-9356-4FBD-B0FD-04508D336B17),
dual,
nonextensible,
pointer_default(unique)
]
interface IComClassTest : IDispatch{
[id(1)] HRESULT Method1(BSTR arg1);
[propget, id(2), bindable, displaybind] HRESULT onevent1([out, retval] VARIANT* pVal);
[propput, id(2), bindable, displaybind] HRESULT onevent1([in] VARIANT newVal);
};
[
uuid(97157E1C-637C-4962-B069-96E70F572A99),
version(1.0),
]
library ATLProject3Lib
原創文章,作者:PVKT,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/145154.html