gpt4 book ai didi

javascript - Angularjs 和 Jquery 日期选择器数据绑定(bind)

转载 作者:行者123 更新时间:2023-11-29 21:51:57 24 4
gpt4 key购买 nike

我正在用 datepicker(JQuery) 做一个项目。当我单击日期选择器中的日期时,除非输入空格或输入,否则它永远不会显示日期。我希望当我点击日期时,显示点击的日期。

我希望在日期选择器中单击日期时输出会自动显示日期。但是我必须先按空格键才能生成/显示日期..请帮忙..这些是我的代码:

  $(document).ready(function () {
$("#datepickerfrom").datepicker({
numberOfMonths: 1,
onSelect: function (selected) {
$("#datepickerto").datepicker("option", selected)
}
});
$("#datepickerto").datepicker({
numberOfMonths: 1,
onSelect: function (selected) {
$("#datepickerfrom").datepicker("option", selected)
}
});
// jQuery object; this demo
});
function GetbyDate(fr, t) {
var from = new Date(t)
};

scope.changeDate = function () {
scope.models = null;
http.get('GetReportList?from=' + scope.filter_fromDate + '&to=' + scope.filter_toDate).success(
function (data) {
scope.models = data;
});
}
              <p class="input-group">

<input type="text" class="form-control" id="datepickerfrom" data-ng-model="filter_fromDate" />

<span class="input-group-btn">
<button type="button" class="btn btn-default">
<i class="glyphicon glyphicon-calendar"></i>
</button>
</span>
{{filter_fromDate}}
</p>

<p class="input-group">
<input type="text" class="form-control" id="datepickerto" data-ng-model="filter_toDate" />
<span class="input-group-btn">
<button type="button" class="btn btn-default">
<i class="glyphicon glyphicon-calendar"></i>
</button>
</span>
{{filter_toDate}}
</p>

最佳答案

是的!我得到了答案..

多亏了这个sample jsfiddle answer .我发现我无法显示日期的原因是我将它包含在 Controller 中。

看看这个:

var PRApp = angular.module('PRApp', []);
PRApp.controller('PRCtrl', ['$scope', '$http', function (scope, http) {

http.get('GetList').success(function (data) {

scope.models = data;
scope.sorting = "-PRDate";

var i = 0;
for (i = 0; i < scope.models.length; i++) {
scope.models[i].id = i;
}
});

scope.getStatus = http.get('GetStatusList').success(function (status) {
scope.StatusList = status
});

function GetbyDate(fr, t) {
var from = new Date(t)
};

scope.changeDate = function () {
scope.models = null;
http.get('GetReportList?from=' + scope.filter_fromDate + '&to=' + scope.filter_toDate).success(
function (data) {
scope.models = data;
});
}
scope.jsonDatetotext = function (jsondate) {
// jsondate format: /Date(#############)/
// substr(6) will remove '/Date('
// parseInt will convert remaing string '#############' to int and ignores ')/'
return new Date(parseInt(jsondate.substr(6)));
};


}]);
PRApp.directive('calendar2', function () {
return {
require: 'ngModel',
link: function (scope, el, el2, attr, ngModel) {

attr.$observe("show", function (val) {
if (val == 'true') {
$(el).datepicker("show");
}
else {
$(el).datepicker("hide");
}
});

attr.$observe("show", function (val) {
if (val == 'true') {
$(el2).datepicker("show");
}
else {
$(el2).datepicker("hide");
}
});

$(el).datepicker({
minDate: '-5Y',
dateFormat: 'MM d, yy',
onSelect: function (dateText) {
scope.$apply(function () {
ngModel.$setViewValue(dateText);
});
}
});

$(el2).datepicker({
minDate: '-5Y',
dateFormat: 'MM d, yy',
onSelect: function (dateText) {
scope.$apply(function () {
ngModel.$setViewValue(dateText);
});
}
});

}
};
});
<span class="input-group-addon">
<span data-ng-click="show=!show" class="glyphicon glyphicon-calendar"></span>
</span>
<input data-show="{{show}}" type="text" name="filter_fromDate" calendar2 data-ng-model="filter_fromDate"
class="form-control" placeholder="mm/dd/yyyy" data-ng-minlength="10" />

</div>

<br />

<div class="input-group">
<span class="input-group-addon">
<span data-ng-click="show=!show" class="glyphicon glyphicon-calendar"></span>
</span>
<input data-show="{{show}}" type="text" name="filter_toDate" calendar2 data-ng-model="filter_toDate"
class="form-control" placeholder="mm/dd/yyyy" data-ng-minlength="10" />


</div>
<br />

<input type="submit" class="btn btn-primary btn-sm" value="GO" />

</div>

关于javascript - Angularjs 和 Jquery 日期选择器数据绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28686331/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com