Click事件未触发(jquery)

时间:2014-02-12 15:40:12

标签: javascript jquery

我有这个非常简单的代码:

 $(function() {
     $( "#datepicker" ).datepicker({ dateFormat: 'yy-mm-dd' });
     $( "#datepicker1" ).datepicker({ dateFormat: 'yy-mm-dd' });
 });

 $(document).ready(function(){
   $("#submit").click(function() {
    var dataString = "datepicker="+$("#datepicker").val()+"&datepicker1="+$("#datepicker1").val();
    $.ajax({
      type: "POST",
      url: "<?php echo $this->baseUrl()?>/index/getrange",
      data: dataString,
      success: function(response)
      {
          $("#table").html(response);
      }
    });
    return false;
   });
 });

html如下:

 <div id="welcome">
 <form action="javascript:void(0);" method="post" id="idForm">
 <p>Select a starting date:<br/>
 <input type="text" id="datepicker" name="datepicker"></p>
 <p>Select an ending date:<br/>
 <input type="text" id="datepicker1" name="datepicker1"></p>
 <input type="submit" value="Search for dates" id="submit">
 </form>
 </div>
 <div id="table"></div>

我甚至无法用firebug调试它,因为它只是没有触发click事件。有什么想法吗?

1 个答案:

答案 0 :(得分:1)

这是工作你可能有没有安装jquery ui?

$(function() {
     $("#datepicker").datepicker({ dateFormat: 'yy-mm-dd' });
     $("#datepicker1").datepicker({ dateFormat: 'yy-mm-dd' });
 });

 $(document).ready(function(){
   $("#submit").click(function() {
    alert("clicked");
    var dataString = "datepicker="+$("#datepicker").val()+"&datepicker1="+$("#datepicker1").val();
    $.ajax({
      type: "POST",
      url: "<?php echo $this->baseUrl()?>/index/getrange",
      data: dataString,
      success: function(response)
      {
          $("#table").html(response);
      }
    });
    return false;
   });
 });

在这里查看.. http://jsfiddle.net/cxybg/1/