如何获得这种效果,如果显示错误消息,窗体不应该失去其不透明性,但如果错误消息被隐藏,只有当窗体悬停时才应用不透明度?没有不透明IF元素是可见的
HTML:
<section>
<form id="form" name="form" action="login.php" method="post">
<ul>
<li>
<span class="er" style="display:none;"> </span>
</li> <br />
<li>
<label for="name">Name</label>
<input type="text" name="name" id="name" />
</li>
<li>
<label for="pass">Password</label>
<input type="password" name="pass" id="pass" />
</li>
</ul>
<input type="submit" value="Log In" />
</form>
</section>
CSS:
section {
opacity: 0.5;
transition: all 1s ease-in-out;
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
-o-transition: all 1s ease-in-out;
}
section:hover{
opacity: 100;
transition: all 1s ease-in-out;
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1 ease-in-out;
-o-transition: all 1s ease-in-out;
}
的jQuery:
$('#form').bind('submit', function (e) {
var self = $(this);
jQuery.post(self.attr('action'), self.serialize(), function (response) {
if ($("#name").val() == "" || $("#pass").val() == "") {
$("span.er").text('Field cannot be blank!');
$("span.er").show();
}
else if (response.success) {
window.location.href='home.php';
} else {
$("span.er").text('Invalid username or password! Please try again.');
$("span.er").show();
}
}, 'json');
e.preventDefault(); //prevent the form being posted
});
我尝试添加这条线上面的任何地方span.er
设为show()
jQuery函数:
$("section").css('opacity', '100');
^只有当span.er
可见时才应用此设置。但是,问题在于,一旦显示错误消息,将应用不透明度设置,而不管span.er
是可见还是隐藏。
在''opacity''中将''1'的''100'更改为''''''''。 – marcosfromero 2011-04-08 13:18:54
完成。感谢那。 – input 2011-04-08 13:29:30
这是否解决了问题? – marcosfromero 2011-04-08 13:32:31