JQ 搜索框获得焦点,和是失去焦点,默认提示显示与消失
2016-11-16 15:13
302 查看
<style type="text/css">
*{
margin:0;
padding: 0;
}
#search{
width: 228px;
height: 22px;
background:pink;
margin:100px auto;
}
#search input{
width: 192px;
height: 22px;
background:url(img/1.png) no-repeat;
border: 0 none;
outline: none;
padding-left: 8px;
color: #ccc;
}
#search button{
width: 28px;
height: 22px;
float: right;
background:url(img/3.png);
border: 0 none;
padding: 0;
}
</style>
</head>
<body>
<div id="search">
<input id="ii" type="text" value="请输入。。。" /><button></button>
</div>
<script type="text/javascript">
$(function(){
$("#ii").focus(function(){
if($(this).val() =="请输入。。。" ){
$(this).val("");
$(this).css("color","#000");
}
});
$("#ii").blur(function(){
if($(this).val() =="" ){
$(this).val("请输入。。。");
$(this).css("color","#ccc");
}
});
})
</script>
</body>
</html>
*{
margin:0;
padding: 0;
}
#search{
width: 228px;
height: 22px;
background:pink;
margin:100px auto;
}
#search input{
width: 192px;
height: 22px;
background:url(img/1.png) no-repeat;
border: 0 none;
outline: none;
padding-left: 8px;
color: #ccc;
}
#search button{
width: 28px;
height: 22px;
float: right;
background:url(img/3.png);
border: 0 none;
padding: 0;
}
</style>
</head>
<body>
<div id="search">
<input id="ii" type="text" value="请输入。。。" /><button></button>
</div>
<script type="text/javascript">
$(function(){
$("#ii").focus(function(){
if($(this).val() =="请输入。。。" ){
$(this).val("");
$(this).css("color","#000");
}
});
$("#ii").blur(function(){
if($(this).val() =="" ){
$(this).val("请输入。。。");
$(this).css("color","#ccc");
}
});
})
</script>
</body>
</html>
相关文章推荐
- 文本框内默认提示————请输入用户姓名(字体灰色),要求: (1)当文本框获得焦点时,默认提示消失 (2)当文本框失去焦点时,如果没有输入新内容,那么则显示原来的灰色字体内容; 如果有新内容输入则判断,如果长度小于10,则提示“姓名长度应该大于10个字符”
- 文本框获得焦点后文本框内的提示文本消失 失去焦点后如果没有输入再显示提示 转
- 点击搜索,获得焦点搜索框为空,失去焦点,显示默认
- 文本框获得焦点后文本框内的提示文本消失 失去焦点后如果没有输入再显示提示
- JavaScript实现文本框中默认显示背景图片在获得焦点后消失的方法
- jquery 获得焦点的时候,焦点时文本框清空,失去焦点时又显示默认文字
- 输入框的提示信息(获得焦点和失去焦点时显示提示信息)
- Win8 在TextBox中设置提示信息,当TextBox获得焦点时消失,失去时验证
- jquery插件小试牛刀:文本框为空时默认文字显示,获得焦点后默认文字消失
- JavaScript实现文本框中默认显示背景图片在获得焦点后消失的方法
- jQuery实现文本域内提示文字,当鼠标点击进文本域后自动消失,文本域失去鼠标焦点后显示提示文字或显示用户输入的文字。
- [Javascript]如何在HTML中实现点击input输入框(获得焦点)后默认提示消失的效果
- 文本框中有默认的文字,写获取焦点和失去焦点的文字显示与消失的效果
- 文章的关键字获得焦点显示提示内容,关键字失去焦点隐藏提示内容
- JavaScript实现文本框中默认显示背景图片在获得焦点后消失的方法
- EditText 获得焦点时hint消失,失去焦点时hint显示
- input 输入框获得/失去焦点时隐藏/显示文字
- js input 鼠标点击清除提示内容,失去焦点还原默认内容的方法
- JS实现文本框获得焦点,文本框里提示信息自动消失
- input 输入框获得/失去焦点时隐藏/显示文字