我希望能够在填写文本框时隐藏某个图像,并且当文本框被清除时我想要显示某个图像。我知道它应该像这样工作,但用图像代替占位符:
$('input:text').focus(function () {
if ($(this).val() === $(this).attr('placeholder')) {
$(this).val('');
}
}).blur(function() {
if ($(this).val() == "") {
$(this).val($(this).attr('placeholder'))
}
});
提前感谢您的回答。
答案 0 :(得分:0)
尝试 -
$('input:text').focus(function () {
$(this).css('background', 'none');
}).blur(function() {
if ($(this).val() == "") {
$(this).css('background', 'url(http://profile.ak.fbcdn.net/hprofile-ak-prn1/71158_111108655596607_6920099_n.jpg) no-repeat left top');
}
});
使用退格键 -