1308 次
3 に答える
2
$('#formId').submit(function (e) {
if ($('#assettype').val() == '') {
e.preventDefault(); //stop form submission
}
});
また
$.validator.addMethod('notNone', function (value, element) {
return (value != '');
}, 'Please select an option');
$("form").validate({
rules: {
assettype: {
required: true,
notNone: true
}
}
});
于 2013-11-12T15:48:55.590 に答える
1
<form id="my_form" method="POST" action="" >
<select id="assettype" name="assettype" class="input-medium required">
<option value="0" >-- Please select --</option>
<option value="1">Printer</option>
<option value="2">Scanner</option>
</select>
</form>
<script type="text/javascript">
$("#my_form").submit(
var check_value = $("#assettype").val();
if (check_value == 0)
{
e.preventDefault();
// prevent the user he has to choose something
// by an alert for example, or background change of the element
$("#assettype").css("background-color", "red");
return false;
}
else
{
// and restore it if it's ok
$("#assettype").css("background-color", "inherit");
}
return true;
});
</script>
于 2013-11-12T15:59:16.700 に答える