Re: [問題] firefox對javascript的支援
※ 引述《tn801534 (踢恩)》之銘言:
: ◆ From: 218.211.217.211
: ※ 編輯: tn801534 來自: 218.211.217.211 (07/09 01:19)
: 推 TonyQ:為什麼你要在onload測selectionstart? @@ 07/09 07:45
: → TonyQ:換句話說,其實可以先判斷他是不是el.stysl.display=='none' 07/09 07:47
: → TonyQ:再決定是否取用 style 07/09 07:47
: → tn801534:應該說正常來講不管是不是display應該都可以取用的到阿 07/09 10:51
: → tn801534:測selectionstart是那個加入按鈕時候的js自己裡面寫的 07/09 10:53
: → tn801534:是為了看瀏覽器有沒有支援八 07/09 10:53
: → TonyQ:我覺得 "在沒有顯示的狀況下" 預期就不會有selection的發生 07/09 11:03
: → TonyQ:所以所謂的[正常來講] , 應該是在有顯示的狀況下確保可取得 07/09 11:03
: → TonyQ:這樣語意來說才是對的 . 07/09 11:03
: → TonyQ:一般程式通常都會把 [沒有預期的事情] 當作錯誤或例外, 07/09 11:04
: → TonyQ:用default值處理 , 可以增加容錯性 , 但也會增加除錯負擔. 07/09 11:05
順手拿原code測一下,其實fx不是停住,而是當錯誤處理了,
順便附上 firebug 除錯的訊息, 來方便佐證討論.
uncaught exception: [Exception...
"Component returned failure code: 0x80004005 (NS_ERROR_FAILURE)
[nsIDOMNSHTMLTextAreaElement.selectionStart]" nsresult: "0x80004005
(NS_ERROR_FAILURE)"
location: "JS frame :: file:///X:/htmltest/test2.html :: start
:: line 5" data: no]
所以把原文改成底下這樣, 會比較像是一個嚴謹的程式設計師的作法...
----------------------------------------------------
try{
if(document.getElementById('area').selectionStart===null){
document.getElementById('c').innerHTML+="null";
}
if(document.getElementById('area').selectionStart===undefined){
document.getElementById('c').innerHTML+="undefined";
}
if(typeof(document.getElementById('area').selectionStart)=='number'){
document.getElementById('c').innerHTML+=
document.getElementById('area').selectionStart;
}
if(document.getElementById('area').selectionStart){
document.getElementById('c').innerHTML+="true";
}
if(!document.getElementById('area').selectionStart){
document.getElementById('c').innerHTML+="false";
}
}catch(e){
document.getElementById('c').innerHTML+="unaccessable";
}
----------------------------------------------------
--
I am a person, and I am always thinking .
Thinking in love , Thinking in life ,
Thinking in why , Thinking in worth.
I can't believe any of what ,
I am just thinking then thinking ,
but worst of all , most of mine is thinking not actioning...
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.128.219.202
推
07/09 11:16, , 1F
07/09 11:16, 1F
→
07/09 11:17, , 2F
07/09 11:17, 2F
→
07/09 12:37, , 3F
07/09 12:37, 3F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
Web_Design 近期熱門文章
PTT數位生活區 即時熱門文章