我有一个带有此验证 javascript 的表单。Js检查是否选择了值。如果两个下拉选项都被选中,则发送表单。
但是发送不起作用。怎么了?
谢谢大家;-)
<script type="text/javascript">
$(document).ready(function(){
$("#submit").click(function (e) {
if($('#species').find(":selected").val()===""){
//alert("empty");
$("#msg1").html("Required");
}
if($('#species2').find(":selected").val()===""){
//alert("empty2");
$("#msg2").html("Requires");
}
e.preventDefault()
});
});
</script>
HTML:
<form method="post" action="send.php">
<label for="species" id="bobo">*Species:</label><br />
<div id="msg1"></div>
<select id="species" name="species" size="1">
<option value="">Please choose a species</option>
<option value="21">Chicken</option>
<option value="28">Turkey</option>
</select>
<br />
<div id="msg2"></div>
<select id="species2" name="species2" size="1">
<option value="">Please choose a species2</option>
<option value="21">Chicken</option>
<option value="28">Turkey</option>
</select>
<br />
<input id="submit" type="submit" value="Submit">
</form>