<html> |
<head> |
<style> |
.title{font:20px red 黑体} |
</style> |
</head> |
<body> |
<form name= "form1" id= "form1" method= "post" action= "" enctype= "multipart/form-data" > |
<span class= "title" >选择要购买的水果?</span><br> |
<input type= "checkbox" name= "cbx" id= "checkbox" value= "苹果" >苹果 |
<input type= "checkbox" name= "cbx" id= "checkbox" value= "西瓜" >西瓜 |
<input type= "checkbox" name= "cbx" id= "checkbox" value= "梨子" >梨子 |
<input type= "checkbox" name= "cbx" id= "checkbox" value= "桃子" >桃子 |
<input type= "checkbox" name= "cbx" id= "checkbox" value= "荔枝" >荔枝 |
<input type= "checkbox" name= "cbx" id= "checkbox" value= "葡萄" >葡萄 |
<input type= "checkbox" name= "cbx" id= "checkbox" value= "草莓" >草莓 |
<input type= "checkbox" name= "cbx" id= "checkbox" value= "桔子" >桔子 |
<input type= "checkbox" name= "cbx" id= "checkbox" value= "山竹" >山竹 |
<input type= "checkbox" name= "cbx" id= "checkbox" value= "榴莲" >榴莲 |
<input type= "checkbox" name= "cbx" id= "checkbox" value= "芒果" >芒果 |
<input type= "checkbox" name= "cbx" id= "checkbox" value= "石榴" >石榴 |
<p><span class= "title" >操作导向:</span><br> |
<input type= "radio" name= "radio1" id= "radio1" value= "购买" >选择好了,去收银台<br> |
<input type= "radio" name= "radio1" id= "radio1" value= "不购买" >重新选择<br> |
</p> |
<input type= "submit" name= "button" id= "button" value= "提交" onClick= "submitClick()" > |
<input type= "reset" name= "button" id= "button" value= "重置" > |
</form> |
<script type= "text/javascript" language= "javascript" > |
//显示结果 |
function submitClick() |
{ |
var selValue=Select_check( "cbx" ); |
if (selValue==0) |
{ |
alert( "你没有做出任何的选择,请选择后再提交" ); |
return false ; |
} |
else |
{ |
var selActionValue=Select_check( "radio1" ); |
if (selActionValue==0) |
{ |
alert( "请你做出购买的选择!" ); |
} |
else |
{ |
strMsg= "你喜欢的水果有:" +selValue; |
strMsg += "\r\n并且你选择了:" +selActionValue + "操作" ; |
alert(strMsg); |
} |
} |
} |
function Select_check(objname) |
{ |
var obj=document.getElementsByName(objname); |
var selArray= new Array(); |
for ( var i=0;i<obj.length;i++) |
{ |
if (obj[i].checked) |
selArray.push(obj[i].value); |
} |
return selArray; |
} |
</script> |
</body> |
</html> |