I have a Jquery UI datepicker control in my asp.net MVC application and it works fine in IE and Firefox but it doens't work in chrome when I click the datepicker button. Here is my Index view:
$(function() {
$('#datepicker').datepicker({
changeMonth: true,
dateFormat: "dd M yy",
changeYear: true,
showButtonPanel: true,
autoSize: true,
altField: "input#txtDate",
onSelect: function(dateText, inst) {
$.ajax({
type: "POST",
url: "/LiveGame/Partial3?gameDate=" + dateText,
dataType: "html",
success: function(result) {
var domElement = $(result);
$("#dvGames").html(domElement);
}
});
}
});
$("#txtDate").val($.format.date(new Date(), 'dd MMM yyyy'));
$('#dvGames').load(
'<%= Url.Action("Partial3", "LiveGame") %>',
{ gameDate: $("#txtDate").val() }
);
});
Here is my partial:
public ActionResult Partial3(string gameDate)
{
return PartialView("Partial3", gameDate);
}
<div id="dvGames" class="cornerdate1">
<%= Url.Action("LiveGame","Partial3") %>
</div>
<input type="text" id="txtDate" name="txtDate" readonly="readonly" class="cornerdate" />
<input id="datepicker" class="cornerimage" type="image" src="../../Content/images/calen开发者_如何学Pythondar.gif" alt="date" />
</div>
Either you can use the Datepicker option from jquery ui
<script>
$(function() {
$( "#datepicker" ).datepicker({
showOn: "button", //add this line
buttonImage: "path/to-your-image.gif", //add this line
buttonImageOnly: true //add this line
});
});
</script>
Or you add a click event on the button:
<script>
$(document).ready(function() {
$("input#datepicker").click(function() {
$("input#datepicker").datepicker("show");
});
});
</script>
In the AJAX success
function you are casting the result to a DOM element. Try simply to do this:
onSelect: function(dateText, inst) {
$('#dvGames').load(
'<%= Url.Action("Partial3", "LiveGame") %>',
{ gameDate: dateText }
);
}
精彩评论