php頁面巢狀html程式碼,,html中js呼叫php中的陣列

守護大白菜發表於2017-09-06
<?php
$lesson_info = array(
  1 =>'語文',
  2 =>'數學',
  3=>'英語',
  4=>'化學',
  5=>'物理',
  6=>'生物',
);
?>

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>H5form表單新特性</title>
</head>
<body>
  <form action="#" method="get">
    <select id="push_type" class="form-control" name="push_type">
      <option value="1">語文</option>
      <option value="2">數學</option>
      <option value="3">英語</option>
      <option value="4">化學</option>
      <option value="5">物理</option>
      <option value="6">生物</option>
    </select>
  </form>
</body>
</html>
<script src="./jquery-1.10.2.min.js"></script>
<script>
$("#push_type").change(function(){
        var id = $(this).val();
        var lesson_info = <?=json_encode($lesson_info)?>;
        alert(lesson_info[id]);
    });
</script>

相關文章