html
<div class="search"> <input type="text" id="inputSearch" class="" value="请输入商品名称"/> </div>
css:
#inputSearch { border: 1px solid #BABEBF; color: #999999; font-size: 14px; height: 17px; padding: 3px 6px 5px 6px; width: 200px; }
#inputSearch.focus{
border: 1px solid red;
}
js:
$(function () { $("#inputSearch").focus(function () { $(this).addClass("focus"); if ($(this).val() == this.defaultValue) { $(this).val(""); } }).blur(function () { $(this).removeClass("focus"); if ($(this).val() == "") { $(this).val(this.defaultValue); } }).keyup(function (e) { if (e.which == 13) { alert("提交后台搜索"); } }); });