在运行这个表单时,本应该在选择value='carte étudiant’时会报错,但尝试多次无反应
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript">
function validation_formulaire(){
if(document.form['information'].identity.value == ('carte étudiant')){
alert("Can't use that");
return false;
}}
</script>
<title>student</title>
</head>
<body>
<form name="information" method="post" action="" onsubmit="return validation_formulaire()">
<label for='prénom'>prénom:</label>
<input type="text" name="prénom" id="prénom">
<label for='nom'>nom:</label>
<input type="text" name="nom" id='nom'>
<label for="papier d'identité">choisir le type de papier d'identité:</label>
<select id='identity' name='identity'>
<option value='passport'>passport</option>
<option value='carte étudiant'>carte étudiant</option>
<option value='driving license'>driving licence</option>
</select>
<label for="passport vaccinal">
Do you have passport vaccinal?
</label>
<input type="checkbox" name="check" id="check">
<button onclick="check()">Yes</button>
<button onclick="uncheck()" >No</button>
<input type="submit">
</form>
</body>
</html>
最后发现 需要将script中的form 改为forms
function validation_formulaire(){
if(document.forms['information'].identity.value == ('carte étudiant')){
alert("Can't use that");
return false;
}}
错误解决