我有这个代码在输入上添加水印。它是页面标题的输入。一切正常。我写了标题,水印消失了(那是对的)。但如果我正在编辑此内容,我的标题就会消失,水印又会重新出现。当输入字段包含内容时,为什么水印会返回?
<script type="text/javascript">
$(document).ready(function() {
var watermark = 'Write your city + state (separated by commas)';
//init, set watermark text and class
$('#edit-title').val(watermark).addClass('watermark');
//if blur and no value inside, set watermark text and class again.
$('#edit-title').blur(function(){
if ($(this).val().length == 0){
$(this).val(watermark).addClass('watermark');
}
});
//if focus and text is watermrk, set it to empty and remove the watermark class
$('#edit-title').focus(function(){
if ($(this).val() == watermark){
$(this).val('').removeClass('watermark');
}
});
});
</script>
抱歉我的英文。感谢您的提示。
答案 0 :(得分:0)