2014-02-12 160 views
0

我有一个非常简单的代码:Click事件不触发(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> 

我甚至不能用萤火虫调试它,因为它是不点击点击事件。任何想法?

+2

为什么不把datepickers的$(document).ready函数里面?另外,jsFiddle? – RobinvdA

+2

似乎在这里工作http://jsfiddle.net/xR6x8/ – j08691

+0

那么为什么它不工作在我的浏览器? (我正在使用firefox) – softwareplay

回答

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/