代码片段,定义要应用水印效果的文本框的样式:
//if blur and no value inside,set watermark text and class again. //if focus and text is watermrk,set it to empty and remove the watermark class 接下来直接在页面上使用: <script type="text/javascript">
//init,set watermark text and class
$(this).val(settings.watermarkText).addClass(settings.className); }
$(this).blur(function () {
if ($(this).val().length == 0) {
$(this).val(settings.watermarkText).addClass(settings.className);
}
});
$(this).focus(function () {
if ($(this).val() == settings.watermarkText) {
$(this).val('').removeClass(settings.className);
}
});
});
}
})(jQuery);
$(document).ready(function () {
$("#tb_search").watermark({
watermarkText: "站内检索",className: "watermark",});
});