季節問題

来源:互联网 发布:软件行业职位分类 编辑:程序博客网 时间:2024/06/06 07:44
<!DOCTYPE html>
<html>
<head>
<script src="/jquery/jquery-1.11.1.min.js">
</script>
<script>
$(document).ready(function(){
  alert("#######");
  
  var checkedSeasons = [];
  $("#b1").click(function() {
  var checkedSeasons = [];
      alert(checkedSeasons);
    $('input:checkbox[name="seasons"]:checked').each(function(){
     checkedSeasons.push($(this).val());
       $('#sp1').text(checkedSeasons);
    });
  });
});
</script>
</head>
<body>
<p>選択した季節: <span id="sp1"></span></p>
<input type="checkbox" name="seasons" value="spring"> 春
<input type="checkbox" name="seasons" value="summer"> 夏
<input type="checkbox" name="seasons" value="autumn"> 秋
<input type="checkbox" name="seasons" value="winter"> 冬
<input type="button" id="b1" value="ボタン1" /><br/>
</body>
</html>