我有一个使用 ajax 发布表单值的表单,并且似乎它没有读取required
表单输入上的属性。谁能告诉我有什么问题?
代码:
<script>
$(function () {
$("#send-email").click(function () {
var subject = $("#subject").val();
var name = $("#name").val();
var email = $("#email").val();
var phone = $("#phone").val();
var message = $("#message").val();
var nationality = document.getElementById("nationality");
var selNationality = nationality.options[nationality.selectedIndex].text;
//
$.post("mail.php", {"subject": subject, "name": name, "email": email, "phone": phone, "nationality": selNationality, "message": message, }, function () {
console.log(subject);
console.log(name);
console.log(email);
console.log(phone);
console.log(selNationality);
console.log(message);
alert("Thanks for contacting us, we will be back to you as soon as possible!");
});
});
});
</script>
<form action="mail.php" method="POST">
<div class="form-row">
<p>Subject</p>
<input type="text" id="subject" name="subject" required>
</select>
</div>
<div class="form-row">
<p>Name</p>
<input type="text" id="name" name="name" required>
</div>
<div class="form-row">
<p>Nationality</p>
<select name="nationality" id="nationality" required>
<option value="">Select Nationality</option>
</select>
</div>
<div class="form-row">
<p>Contact number</p>
<input type="text" id="phone" name="phone">
</div>
<div class="form-row">
<p>Email</p>
<input type="text" id="email" name="email" required>
</div>
<div class="form-row">
<p>Message</p>
<textarea style="width:590px;height:100px;" id="message" name="message" cols="80" rows="12" required></textarea>
</div>
<div class="form-row">
</div>
<div class="form-row">
<input type="submit" onclick="return false;" id="send-email" value="SEND" name="send"/>
</div>
</form>