问题
I am using jQuery UI picker and I am wondering if it's possible when someone pick a date, it automatically redirect them to the URL like so:
index.php?date=2013-10-15
Here's the plug-in I am using.
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>
Date: <input type="text" id="datepicker" />
回答1:
1) What you need is window.location.href, which is the used to redirect the page. You can customize way the window to opened.
2) Once you select the date in datepicker (onSelect
), you can combine the change
event as @T.J. Crowder said in his answer.
You can try like this
$("#datepicker")
.datepicker({
dateFormat: "yy-mm-dd",
onSelect: function(dateText) {
$(this).change();
}
})
.change(function() {
window.location.href = "index.php?date=" + this.value;
});
回答2:
Try this:
$(function () {
$("#datepicker").datepicker({
dateFormat: "yy-mm-dd",
onSelect: function () {
window.open(document.URL + '?date=' + this.value);
}
});
});
Demo here
回答3:
I hope this will work out as per your requirement.
Date:
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
function myFunc(){
var dateData = $("#datepicker").val();
if(dateData != '' ){
var url = "http://www.index.php?date="+ dateData ;
window.open(url);
}
}
</script>
<body>
<p>Date: <input type="text" id="datepicker" onchange="myFunc();" /></p>
</body>
来源:https://stackoverflow.com/questions/19374587/calendar-change-url-on-select-with-jquery-ui-datepicker