为什么java脚本不工作?

时间:2017-02-13 09:00:03

标签: javascript html

我有这个代码,但我在chrome中遇到错误,因为没有定义load_new_content_dr ......

<html>
<head>

<script lang="javascript" src="http://code.jquery.com/jquery-latest.js">
  $(document).ready(function(){

    $("#Dr_name").change(load_new_content_dr()); 
    $("#day").change(load_new_content_day());
});
function load_new_content_dr(){
     var selected_option_value=$("#Dr_name option:selected").val();

     $.post("_add_reservasion.php", {option_value: selected_option_value},
         function(data){ 
              $("#day").html(data);
              alert(data);
       }
     );

     $.post("__add_reservasion.php",
      function(data){
        $("#time").html(data);
        alert(data);

      }
    );
}

function load_new_content_day(){
      var selected_day = $("#day option:selected").val();
  $.post("__add_reservasion.php", {selected_day:selected_day},
    function(data){
      $("#time").html(data);
      alert(data);

    }
  );
}

  </script>
</head>
  <body>
 ...

some codes for connecting database and other stiffs...


...
<!--======================doctore name=========================-->
<p>doctor name:</p>
      <select name="Dr_name" id = "Dr_name" form="new" onchange="load_new_content_dr()">
        <option value="null"></option>
        <?php
          while($row = mysqli_fetch_array($table))
          {
            $name = $row["name"];
            if(isset($_POST["Dr_name"]) && $_POST["Dr_name"] == $name)
              echo "<option value =$name selected>$name</option>";
            else
              echo "<option value =$name>$name</option>";

          }
        ?>

      </select><br><br><br>
<!--=========== day===============\\-->
<p>reservation day:</p>
<select name="day" id="day" form="new" onchange="load_new_content_day()"></select><br><br><br>
<!--hour-->
<p>time:</p>
      <select name="time" id = "time" form = "new"></select><br><br>


<input type="submit" value="save">
<input type="submit" name="cancel" value="cancel">
    </form>
  </body>
</html>

似乎java脚本代码不起作用,因为首先在页面加载时它们应该进行一些更改而它们不会:(

1 个答案:

答案 0 :(得分:6)

如果指定脚本标记的src属性,则忽略其文本内容。您应该使用两个脚本标记:

<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
  // ...
</script>