<form action="index.php" method="POST" id="addcredits">
<input type="text" id="name" placeholder="Username"><br /><br />
<input type="text" id="amount" placeholder="credits amount"><br /><br />
<input type="submit" id="submit">
</form>
$(document).ready(function() {
$("#addcredits").submit(function(event) {
event.preventDefault();
var username = $("#name");
var amount = $("#amount");
var submit = $("#amount");
var error = $("#error");
if (username.val() != null && amount.val() != null) {
console.log("hi");
} else {
error.html("One of the fields were empty..");
error.fadeIn("fast");
setTimeout(function() {
error.fadeOut("fast");
}, 5000);
}
});
});
由于占位符文本,用户名和金额字段始终不为空。有没有办法让 jquery 忽略占位符?