如何獲得這種效果,如果顯示錯誤消息,窗體不應該失去其不透明性,但如果錯誤消息被隱藏,只有當窗體懸停時才應用不透明度?沒有不透明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