搜索框带有搜索提示点击消失代码实例
搜索框大家一定都不陌生,因为随时都可以用到,比较人性化的搜索框都有这样的效果,默认情况有搜索提示,点击搜索框,提示内容消失,下面就通过代码实例介绍一下如何实现此功能。
代码如下:
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
<!DOCTYPE html>
<
html
>
<
head
>
<
meta
charset
=
" utf-8"
>
<
title
>蚂蚁部落</
title
>
<
script
type
=
"text/javascript"
>
window.onload=function(){
var keyword=document.getElementById("keyword");
keyword.onfocus=function(){
if(this.value=="请输入关键词"){
this.value="";
}
}
keyword.onblur=function(){
if(this.value==""){
this.value="请输入关键词";
}
}
}
</
script
>
</
head
>
<
body
>
<
input
type
=
"text"
value
=
"请输入关键词"
id
=
"keyword"
/>
<
input
type
=
"button"
value
=
"点击提交"
id
=
"tijiao"
/>
</
body
>
</
html
>
|
原文发布时间为:2017-3-11
本文作者:admin
本文来自云栖社区合作伙伴“蚂蚁部落”,了解相关信息可以关注蚂蚁部落
原文链接:搜索框带有搜索提示点击消失代码实例