国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > JS > 正文

JS初學者實例教程(8):單選按鈕、復選按鈕

2024-09-06 12:40:51
字體:
來源:轉載
供稿:網友

上一篇js教程學習了:js初學者實例教程(7):注冊表單驗證

實例八

本實例主要介紹了document對象讀取表單元素的使用(單選按鈕、復選按鈕的使用)

 <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
 <head>
  <title> new document </title>
  <meta name="generator" content="editplus">
  <meta name="author" content="">
  <meta name="keywords" content="">
  <meta name="description" content="">
  <script language="javascript">
  <!--
 function sel_coun(){
  var country = document.form1.country.length; //得到radio個數
 for(var i=0;i<country;i++){
 if(form1.country[i].checked){
 alert(form1.country[i].value);
 break;
 }else{
 continue;
 }
 }
 }
 function sel_love(){
  var country = document.form1.love.length; //得到checkbox個數
  var love =""; //new array();
  for(var i=0;i<country;i++){ 
  if(form1.love[i].checked){ 
  love+=form1.love[i].value+"、"; 
  }
  }
  love = love.substring(0,love.lastindexof("、"));
  alert("你的愛好有:"+love)
 }
  //-->
  </script>
 </head>
 <body>
 <form name ="form1" method=post action="">
 單選應用
<input type="radio" name="country" value="中國" checked>中國
<input type="radio" name="country" value="法國">法國
<input type="radio" name="country" value="美國">美國
<input type="button" value="提交" onclick="sel_coun();"/><br/>
復選應用
<input type="checkbox" name="love"  value="打球">打球
<input type="checkbox" name="love" value="游泳">游泳
<input type="checkbox" name="love" value="看書">看書
<input type="checkbox" name="love" value="跳舞">跳舞
<input type="button" value="提交" onclick="sel_love();"/><br/>
 </form>
 </body>
</html>

效果演示:


[ctrl+a 全部選擇 提示:你可先修改部分代碼,再按運行]

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 孝昌县| 芜湖县| 天祝| 上林县| 苍梧县| 桂阳县| 民乐县| 嘉禾县| 界首市| 沾益县| 和龙市| 盘锦市| 新干县| 东丽区| 霞浦县| 东兰县| 郓城县| 长泰县| 越西县| 徐水县| 西峡县| 江门市| 小金县| 西吉县| 大足县| 九江县| 宣城市| 杭锦旗| 文山县| 工布江达县| 巴马| 雷山县| 江山市| 安岳县| 收藏| 陈巴尔虎旗| 神池县| 洞头县| 舒兰市| 巴里| 吴川市|