Posted on 2007-03-22 14:47
Jaunt 閱讀(1562)
評(píng)論(4) 編輯 收藏 所屬分類:
JavaScript
在網(wǎng)上看了一下js代碼感覺有點(diǎn)用,就轉(zhuǎn)過來,也算是俺的一點(diǎn)小練習(xí)。
<!
DOCTYPE?html?PUBLIC?"-//W3C//DTD?XHTML?1.0?Transitional//EN"
????"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
<
html?
xmlns
="http://www.w3.org/1999/xhtml"
?xml:lang
="en"
?lang
="en"
>
<
head
>
??
<
title
></
title
>
??
<
style?
type
="text/css"
>
??#search
{
????border
:
1px?solid?#ccc
;
????color
:
#999
;
??
}
??
</
style
>
??
<
script?
type
="text/javascript"
>
??
<!--
????
function
?addEvent(elm,?evType,?fn,?useCapture)
????????
//
?addEvent?and?removeEvent
????????
//
?cross-browser?event?handling?for?IE5+,??NS6?and?Mozilla
????????
//
?By?Scott?Andrew
????{
??????????
if
?(elm.addEventListener){
????????????elm.addEventListener(evType,?fn,?useCapture);
????????????
return
?
true
;
??????????}?
else
?
if
?(elm.attachEvent){
????????????
var
?r?
=
?elm.attachEvent(
"
on
"
+
evType,?fn);
????????????
return
?r;
??????????}?
else
?{
????????????alert(
"
Handler?could?not?be?removed
"
);
??????????}
????}
????
function
?externalLinks(){???????
//
設(shè)定屬性rel為external的連接在新頁(yè)面打開
????????
if
(
!
document.getElementsByTagName)?
return
?;
????????
var
?anchors
=
document.getElementsByTagName(
"
a
"
);
????????
for
(
var
?i
=
0
;i
<
anchors.length;i
++
){
????????????anchor
=
anchors[i];
????????????
if
(anchor.getAttribute(
"
href
"
)
&&
anchor.getAttribute(
"
rel
"
)
==
"
external
"
){
????????????????anchor.setAttribute(
"
target
"
,
"
_blank
"
);
????????????}
????????}
????}
????
function
?onSearchFocus(){???????????
//
搜索框獲取焦點(diǎn)時(shí)
????????
var
?search
=
document.getElementById(
"
search
"
);
????????
if
(search.value
==
"
請(qǐng)輸入關(guān)鍵字
"
){????
//
如果輸入框內(nèi)容是“請(qǐng)輸入關(guān)鍵字”,則清空內(nèi)容,并設(shè)頂文字顏色為黑色
????????????search.value
=
""
;
????????????search.style.color
=
"
#000
"
????????}
????}
????
function
?onSearchBlur(){????????????
//
搜索框失去焦點(diǎn)時(shí)
????????
var
?search
=
document.getElementById(
"
search
"
);
????????
if
(search.value
==
""
){???????????????
//
如果輸入框內(nèi)容為空,則設(shè)定文字顏色為灰色,內(nèi)容為“請(qǐng)輸入關(guān)鍵子”
????????????search.style.color
=
"
#999
"
;
????????????search.value
=
"
請(qǐng)輸入關(guān)鍵字
"
????????}
????}
????addEvent(window,
"
load
"
,externalLinks)
??
-->
??
</
script
>
</
head
>
<
body
>
<
p
>
[External?links]
<
br?
/>
<
a?
href
="http://www.qq.com"
?rel
="external"
>
QQ.com
</
a
><
br?
/>
<
a?
href
="http://www.163.com"
?rel
="external"
>
163.com
</
a
><
br?
/>
</
p
>
<
p
>
[internal?Links]
<
br?
/>
<
a?
href
="http://www.blueidea.com"
?rel
="internal"
>
BlueIdea.com
</
a
><
br?
/>
<
a?
href
="http://www.51js.com"
?rel
="internal"
>
51Js.com
</
a
><
br?
/>
</
p
>
<
p
>
[Input?Test]
<
br?
/>
<
input?
type
="text"
?id
="search"
?value
="請(qǐng)輸入關(guān)鍵字"
?size
="20"
?onFocus
="onSearchFocus()"
?onblur
="onSearchBlur()"
?
/>
</
p
>
</
body
>
</
html
>
from index:http://www.cnitblog.com/yemoo/archive/2006/06/25/12827.html