<!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>

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 Jerry 的頭像
    Jerry

    Bug倉庫 // 程式日記

    Jerry 發表在 痞客邦 留言(0) 人氣()