
<!--Google 468*60橫幅廣告開始--><script type="text/javascript"><!-- google_ad_client = "pub-7343546549496470"; google_ad_width = 468; google_ad_height = 60; google_ad_format = "468x60_as"; google_ad_type = "image"; //2007-07-26: CSDN google_ad_channel = "6063905817"; google_color_border = "6699CC"; google_color_bg = "E6E6E6"; google_color_link = "FFFFFF"; google_color_text = "333333"; google_color_url = "AECCEB"; google_ui_features = "rc:6"; //--> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script><!--Google 468*60橫幅廣告結(jié)束--><!--新Google 468*60橫幅廣告開始--><script type="text/javascript"><!-- google_ad_client = "pub-7343546549496470"; /* 468x60, 創(chuàng)建于 08-8-6 */ google_ad_slot = "7368701459"; google_ad_width = 468; google_ad_height = 60; //--> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script><!--新Google 468*60橫幅廣告結(jié)束-->
開發(fā)準(zhǔn)備工作
相關(guān)有價(jià)值的網(wǎng)站
中文firefox開發(fā)論壇地址 http://www.firefox.net.cn/newforum
討論IE與Netscape區(qū)別的 http://www-128.ibm.com/developerworks/web/library/wa-ie2mozgd/
http://www.w3schools.com/
firefox開發(fā)工具
javascript控制臺(tái)(firefox工具中)
dominspector(forefox工具中,需要安裝的時(shí)候選擇自定義安裝-開發(fā)工具)
http://www.hacksrus.com/~ginda/venkman/
以下所有IE指IE6.0
驗(yàn)證是否是IE瀏覽器(來(lái)自于googlejs)
- var agt=navigator.userAgent.toLowerCase();
- var is_ie=(agt.indexOf( "msie" )!=-1&&document.all);
事件委托方法
IE
- document.body.onload=inject; //Functioninject()在這之前已被實(shí)現(xiàn)
- document.body.onload=inject();
- document.body.onload= new Function( 'inject()' );
通過(guò)其他方式傳遞對(duì)象
- if (isIE)
- thistable.attachEvent( "onmousedown" ,OnClickChangeTdBackColor);
- //thistable.onmousedown=OnClickChangeTdBackColor;
- else //dealfirefox
- {
- for ( var i=0;i<thistable.rows.length;i++)
- {
- var rowObj=thistable.rows[i];
- for ( var j=0;j<rowObj.cells.length;j++)
- {
- var cellObj=rowObj.cells[j];
- cellObj.setAttribute( "onmousedown" , "OnClickChangeTdBackColor(this)" );
- }
- //alert(rowObj.cells[0].tagName);
- }
- }
在FireFox下編寫事件處理函數(shù)是很麻煩的事.
因?yàn)镕ireFox并沒(méi)有window.event.如果要得到event對(duì)象,就必須要聲明時(shí)間處理函數(shù)的第一個(gè)參數(shù)為event.
所以為了兼容IE與FireFox,一般的事件處理方法為:
- btn.onclick=handle_btn_click;
- function handle_btn_click(evt)
- {
- if (evt== null )evt=window.event; //IE
- //處理事件.
- }
但對(duì)于一些復(fù)雜的程序,某寫函數(shù)根本就不是直接與事件掛鉤的.如果要把event傳進(jìn)該參數(shù),那么所有的方法都要把event傳來(lái)傳去..這簡(jiǎn)直就是噩夢(mèng).
下面介紹一個(gè)解決這個(gè)麻煩事的方法,與原理.
JScript中,函數(shù)的調(diào)用是有一個(gè)func.caller這個(gè)屬性的.
例如
- function A()
- {
- B();
- }
- function B()
- {
- alert(B.caller);
- }
另外,函數(shù)有一個(gè)arguments屬性.這個(gè)屬性可以遍歷函數(shù)當(dāng)前執(zhí)行的參數(shù):
- function myalert()
- {
- var arr=[];
- for ( var i=0;i
- arr[i]=myalert.arguments[i];
- alert(arr.join( "-" ));
- }
- alert( "hello" , "world" ,1,2,3)
(arguments的個(gè)數(shù)與調(diào)用方有關(guān),而與函數(shù)的參數(shù)定義沒(méi)有任何關(guān)系)
根據(jù)這兩個(gè)屬性,我們可以得到第一個(gè)函數(shù)的event對(duì)象:
- btn.onclick=handle_click;
- function handle_click()
- {
- showcontent();
- }
- function showcontent()
- {
- var evt=SearchEvent();
- if (evt&&evt.shiftKey) //如果是基于事件的調(diào)用,并且shift被按下
- window.open(global_helpurl);
- else
- location.href=global_helpurl;
- }
- function SearchEvent()
- {
- func=SearchEvent.caller;
- while (func!= null )
- {
- var arg0=func.arguments[0];
- if (arg0)
- {
- if (arg0.constructor==Event) //如果就是event對(duì)象
- return arg0;
- }
- func=func.caller;
- }
- return null ;
- }
在該例子運(yùn)行時(shí),
SearchEvent.caller就是showcontent,但是showcontent.arguments[0]是空.所以func=func.caller時(shí),func變?yōu)閔andle_click.
handle_click被FireFox調(diào)用,雖然沒(méi)有定義參數(shù),但是被調(diào)用時(shí),第一個(gè)參數(shù)就是event,所以handle_click.arguments[0]就是event!
針對(duì)上面的知識(shí),我們可以結(jié)合prototype.__defineGetter__來(lái)實(shí)現(xiàn)window.event在FireFox下的實(shí)現(xiàn):
下面給出一個(gè)簡(jiǎn)單的代碼..有興趣的可以補(bǔ)充
- if (window.addEventListener)
- {
- FixPrototypeForGecko();
- }
- function FixPrototypeForGecko()
- {
- HTMLElement.prototype.__defineGetter__( "runtimeStyle" ,element_prototype_get_runtimeStyle);
- window.constructor.prototype.__defineGetter__( "event" ,window_prototype_get_event);
- Event.prototype.__defineGetter__( "srcElement" ,event_prototype_get_srcElement);
- }
- function element_prototype_get_runtimeStyle()
- {
- //returnstyleinstead...
- return this .style;
- }
- function window_prototype_get_event()
- {
- return SearchEvent();
- }
- function event_prototype_get_srcElement()
- {
- return this .target;
- }
- function SearchEvent()
- {
- //IE
- if (document.all)
- return window.event;
-
- func=SearchEvent.caller;
- while (func!= null )
- {
- var arg0=func.arguments[0];
- if (arg0)
- {
- if (arg0.constructor==Event)
- return arg0;
- }
- func=func.caller;
- }
- return null ;
- }
- </body></html>
因?yàn)閒irefox與IE都支持DOM,因此使用obj.parentNode是不錯(cuò)選擇.
IE
obj.parentElement
firefox
obj.parentNode
asp.net中UniqueID和clientID的區(qū)別
要使用document.getElementById方法,則使用控件的時(shí)候要這樣來(lái)作
"javascript:OnSelectSubCatalog(/""+subCatalog_drp.ClientID+"/","+catalogIDX+","+catID.ToString()+")";
調(diào)用Select元素的區(qū)別
移出一個(gè)選擇項(xiàng)
________________________________________
IE:sel.options.remove(sel.selectedIndex);
firefox:
增加選擇項(xiàng):
________________________________________
IE:subCatalog.add(newOption(text,value));
firefox:
varopnObj=document.createElement("OPTION");
//opnObj.id=optionID;
opnObj.value=value;
opnObj.text=text;
subCatalog.appendChild(opnObj);
cursor:handVScursor:pointer
firefox不支持hand,但ie支持pointer,所以建議統(tǒng)一使用pointer。
作者: zhaoyang3402@126.com(Tony)
<!--新Google 468x15 橫鏈接單元開始--><script type="text/javascript"><!-- google_ad_client = "pub-7343546549496470"; /* 468x15 橫鏈接單元 */ google_ad_slot = "5785741422"; google_ad_width = 468; google_ad_height = 15; //--> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script><!--新Google 468x15 橫鏈接單元結(jié)束-->
<!-- Google Reader shared發(fā)布代碼開始 --><script type="text/javascript" src="http://www.google.com/reader/ui/publisher.js"></script><script type="text/javascript" src="http://www.google.com/reader/public/javascript/user/00697638153916680411/state/com.google/broadcast?n=5&callback=GRC_p%28%7Bc%3A%22green%22%2Ct%3A%22%5Cu8FD9%5Cu4E9B%5Cu6587%5Cu7AE0%5Cu4E5F%5Cu503C%5Cu5F97%5Cu4E00%5Cu770B%22%2Cs%3A%22false%22%7D%29%3Bnew%20GRC"></script><!-- Google Reader shared發(fā)布代碼結(jié)束 -->
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
