我在让我的onFocus
和onBlur
事件正常工作时遇到了一些问题
这是我得到的
var var1
$("input").focus(function() {
var1 = $(this).val()
if ( $(this).val()==var1) {
$(this).val('').css({'color': "#000", 'font-style': 'normal', 'font-weight': 'bold'});
}
$(this).css({'background-color':'#d7df23' });
});
$("input").blur(function() {
if ( $(this).attr("value")=="") {
$(this).val(var1).css({'color': "#666", 'font-style': 'italic', 'font-weight': 'normal'});
}
$(this).css({'background-color':'#EEEEEE' });
});
这是我的 HTML
<input type="text" id="tbTitle" value="Title">
<input type="text" id="tbTitle1" value="Title1">
<input type="text" id="tbTitle2" value="Title2">
如果您不更改文本框的值,则此方法有效。
基本上我想获取输入的原始值并将其存储在 var 中,然后如果该字段为空白,则将原始值放回原处。
目前它将文本框中的任何内容的值放在焦点上
有没有办法存储原始值并仅将其更改为该值onBlur
?
这是我的jsfiddle的链接