<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=BIG5"> | |
<title>第一支javaScript</title> | |
</head> | |
<body> | |
<form action="#" method="post" class="demoForm" id="demoForm"> | |
<fieldset> | |
<legend>Demo: Get Value of Selected</legend> | |
<p>Select a shipping method:</p> | |
<p> | |
<label><input type="radio" name="ship" value="a" checked /> a)Standard Ground</label> | |
<label><input type="radio" name="ship" value="b" />b) Second Day</label> | |
<label><input type="radio" name="ship" value="c" /> c)Overnight</label> | |
<label><input type="radio" name="ship" value="d" /> d)Pick up</label> | |
</p> | |
<p><button type="button" name="getVal">Get Value of Selected</button></p> | |
</fieldset> | |
</form> | |
</Script> | |
<script type="text/javascript"> | |
// to remove from global namespace | |
(function() { | |
function getRadioVal(form, name) { | |
var val; | |
var radios = form.elements[name]; | |
for (var i=0, len=radios.length; i<len; i++) { | |
if ( radios[i].checked ) { | |
val = radios[i].value; | |
break; | |
} | |
} | |
return val; | |
} | |
document.forms['demoForm'].elements['getVal'].onclick = function() { | |
alert( 'The selected radio button\'s value is: ' + getRadioVal(this.form, 'ship') ); | |
}; | |
// disable submission of all forms on this page | |
for (var i=0, len=document.forms.length; i<len; i++) { | |
document.forms[i].onsubmit = function() { return false; }; | |
} | |
}()); | |
</script> | |
</body> | |
</html> |
2016年4月29日 星期五
網頁試題
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言