Last active
August 29, 2015 14:04
-
-
Save webspace-jp/f17d27fec0498a5be124 to your computer and use it in GitHub Desktop.
BootstrapでjQuery UIのDatepickerを利用する(From / To機能付き)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Insert title here</title> | |
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> | |
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css"> | |
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.0/themes/smoothness/jquery-ui.css"> | |
<body> | |
<div class="container"> | |
<form class="form-inline"> | |
<div class="form-group"> | |
<div class="input-group"> | |
<input type="text" id="begin" class="form-control datepicker" data-end="#end" value="2014/08/10" size="12"> | |
<span class="input-group-btn"> | |
<button class="btn btn-default" type="button" data-toggle="datepicker" data-target="#begin"> | |
<span class="glyphicon glyphicon-calendar"></span></button> | |
</span> | |
</div> | |
</div> | |
~ | |
<div class="form-group"> | |
<div class="input-group"> | |
<input type="text" id="end" class="form-control datepicker" data-begin="#begin" value="2014/08/20" size="12"> | |
<span class="input-group-btn"> | |
<button class="btn btn-default" type="button" data-toggle="datepicker" data-target="#end"> | |
<span class="glyphicon glyphicon-calendar"></span></button> | |
</span> | |
</div> | |
</div> | |
</form> | |
</div> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> | |
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.0/jquery-ui.min.js"></script> | |
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.0/i18n/jquery-ui-i18n.min.js"></script> | |
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> | |
<script> | |
$(function(){ | |
$.datepicker.setDefaults( $.datepicker.regional[ "ja" ] ); | |
$(".datepicker").datepicker({ | |
beforeShow: function (input, inst) { | |
var $this = $(input); | |
var begin = $this.data('begin') || ''; | |
if (begin) { | |
$this.datepicker("option", "minDate", $(begin).val()); | |
} | |
var end = $this.data('end') || ''; | |
if (end) { | |
$this.datepicker("option", "maxDate", $(end).val()); | |
} | |
}, | |
onSelect: function (dateText, inst) { | |
var $this = $(inst.input); | |
var begin = $this.data('begin') || ''; | |
if (begin) { | |
$(begin).datepicker("option", "maxDate", dateText); | |
} | |
var end = $this.data('end') || ''; | |
if (end) { | |
$(end).datepicker("option", "minDate", dateText); | |
} | |
}, | |
}); | |
$('[data-toggle=datepicker]').each(function () { | |
var target = $(this).data('target') || ''; | |
if (target) { | |
$(this).bind("click", function () { | |
$(target).datepicker("show"); | |
}); | |
} | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment