很抱歉,如果这是一个愚蠢的问题,但我整天都在寻找,而且我自己也找不到。
代码:
HTML
<input type="text" value="E-mail" class="email-inactive" onFocus="toggleText(this);" onBlur="toggleText(this);">
JS
var toggleText = function (el)
{
var v = el.value;
//Remove text to allow editing
if(v=="E-mail") {
el.value = "";
el.className = "email-active";
}
else {
//Remove whitespace
if(v.indexOf(" ")!=-1) {
split = v.split(" ").join("");
v = split;
}
//Change to inactive state
if(v=="") {
el.value = "E-mail";
el.className = "email-inactive";
}
}
}
CSS
.email-active {
font-family: 'Lato';
border-radius: 4px;
font-weight: 300;
color: rgba(255, 255, 255, 0.79);
height: 44px;
padding: 0 8px;
width: 350px;
background-color: rgba(255, 255, 255, 0.33);
vertical-align: bottom;
border-color: #2980b9;
-webkit-transition: all 0.30s ease-in-out;
-moz-transition: all 0.30s ease-in-out;
-ms-transition: all 0.30s ease-in-out;
-o-transition: all 0.30s ease-in-out;
outline: none;
border: 1px solid #DDDDDD;
}
.email-active:focus {
box-shadow: 0 0 5px rgba(81, 203, 238, 1);
border: 1px solid rgba(81, 203, 238, 1);
border-radius: 4px;
}
.email-inactive {
font-family: 'Lato';
font-weight: 300;
color:rgba(255, 255, 255, 0.26);
height: 44px;
padding: 0 8px;
width: 350px;
background-color: rgba(255, 255, 255, 0.33);
vertical-align: bottom;
border: 0;
border-radius: 4px;
}
答案 0 :(得分:0)
您可以使用jQuery将事件替换为事件而不是帮助程序
Template.emailTemplate.events({
'focus #email':function(event){
event.preventDefault();
$(event.target).removeClass('email-inactive').addClass('email-active')
},
'focusout #email':function(event){
event.preventDefault();
$(event.target).removeClass('email-active').addClass('email-inactive')
}
});