我现在在单页中有2个日期选择器当我点击datepicker2时我检查它是否选择了datepicker1如果没有然后尝试将焦点移到textbox1但它仍然是在textbox2上的焦点 这是我的代码 HTML
<div class="row">
<div class="col-sm-3"> </div>
<div class="col-sm-3">
<div class="form-horizontal">
<div class="control-group">
<div class="controls">
<div class="input-group">
<label for="date-picker-1" class="input-group-addon btn"><span class="glyphicon glyphicon-calendar"></span>
</label>
<input id="date-picker-1" type="text" class="date-picker form-control" />
</div>
</div>
</div>
</div>
</div>
<div class="col-sm-3">
<div class="form-horizontal">
<div class="control-group">
<div class="controls">
<div class="input-group">
<label for="date-picker-2" class="input-group-addon btn"><span id="calender2" class="glyphicon glyphicon-calendar"></span>
</label>
<input id="date-picker-2" type="text" class="date-picker form-control" />
</div>
</div>
</div>
</div>
</div>
</div>
的Javascript
$("#date-picker-1").datepicker({
dateFormat: "dd-mm-yy"
});
$("#date-picker-1").on("change", function () {
var id = $(this).attr("id");
var timePicker1Value=document.getElementById("date-picker-1").value.trim();
if (timePicker1Value ==""){
showMessage("green", "Please select 'From Date' first", "");
}
var val = $("label[for='" + id + "']").text();
$("#msg").text(val + " changed");
});
$( "#calender2" ).off("click").on("click",function() {
var timePicker1Value=document.getElementById("date-picker-1").value.trim();
if (timePicker1Value ==""){
showMessage("green", "Please select 'From Date' first", "");
$("#date-picker-1").focus();
}
else
{
$("#date-picker-2").datepicker({
dateFormat: "dd-mm-yy"
});
datepicker2();
}
});
function datepicker2(){
$("#date-picker-2").on("change", function () {
var id = $(this).attr("id");
var val = $("label[for='" + id + "']").text();
$("#msg").text(val + " changed");
});
}