close
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
span{
color: darkRed;
line-height: 40px;
}
</style>
</head>
<body>
<form id="form" action="http://www.google.com">
<select id="select">
<option>aa</option>
<option>bb</option>
<option>cc</option>
<option>dd</option>
</select>
<h2>
你選到第<span id="selectedIndex"></span>個,
值是<span id="value"></span>
</h2>
<input type="checkbox" id="checkbox">把我打勾才能送出喔<br>
<span id="youshouldcheck"></span><br>
<input type="submit" >
</form>
<script type="text/javascript">
document.getElementById('select').onchange=function(){
document.getElementById('selectedIndex').innerHTML=this.selectedIndex+1;
document.getElementById('value').innerHTML=this.options[this.selectedIndex].value;
}
document.getElementById('form').onsubmit=function(e){
e.preventDefault();
if(!document.getElementById('checkbox').checked){
document.getElementById('youshouldcheck').innerHTML='你應該要打勾喔';
}else{
e.target.submit();
}
}
</script>
</body>
</html>
全站熱搜