html给搜索框加默认提示,asp.net使用jquery实现搜索框默认提示功能

文本框中创建默认文本提示

通常用户在搜索内容时,在文本框输入内容前,文本框都会给出默认提示,提示用户输入正确的内容进行搜索。

当文本框获得焦点,如果文本框内容跟提示内容一样,提示内容会自然消失。

当文本框没有任何值并失去焦点,文本框内容会重新生成默认提示。

为了实现上面的需求,代码如下:

.text

{

border: #0a8fda solid 1px;

color: #cccccc;

font-style:italic;

background: #fff url(img/input.gif);

padding: 5px;

}

.text-focus

{

border: solid 1px #f50;

background: #fff url(img/input.gif);

padding: 5px;

}

$(document).ready(function () {

var txtSearch = $("#");

$("#txtSearch").focus(function () {

if (txtSearch.val() == this.title) {

txtSearch.val("");

this.className = "text-focus";

}

});

$("#txtSearch").blur(function () {

if (txtSearch.val() == "") {

txtSearch.val(this.title);

this.className = "text";

}

});

txtSearch.blur();

});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值