gpt4 book ai didi

javascript - Angular js 中的 Twitter Bootstrap 日期选择器

转载 作者:数据小太阳 更新时间:2023-10-29 04:24:23 24 4
gpt4 key购买 nike

我正在使用 twitter bootstrap、Angular js 和 Taffy DB 构建应用程序。

JavaScript:

  $(function() {
$('#datepicker').datepicker();
});

$scope.submit = function () {
console.log($scope.eventdate);
};

HTML:

<label for="eventdate">Date</label>
<div class="input-append date" id="datepicker" data-date-format="dd-mm-yyyy">
<input class="span2" size="20" type="text" id="eventdate" ng-model="eventdate">
<span class="add-on"><i class="icon-th"></i></span>
</div>

但是 console.log($scope.eventdate); 是未定义的。

请多多指教

最佳答案

如果您决定使用 Angular,请将 datepicker 放入指令中:

JS

app.controller('MainCtrl', function($scope) {
$scope.var1 = '12-07-2013';
});


app.directive('datetimez', function() {
return {
restrict: 'A',
require : 'ngModel',
link: function(scope, element, attrs, ngModelCtrl) {
element.datetimepicker({
dateFormat:'dd-MM-yyyy',
language: 'en',
pickTime: false,
startDate: '01-11-2013', // set a minimum date
endDate: '01-11-2030' // set a maximum date
}).on('changeDate', function(e) {
ngModelCtrl.$setViewValue(e.date);
scope.$apply();
});
}
};
});

HTML

 <div class="container container-fluid" ng-controller="MainCtrl">
var1={{var1}}
<form class="form-horizontal" novalidate name="form" ng-submit="submit()">
<div class="well">
<div id="date" class="input-append" datetimez ng-model="var1">
<input data-format="MM-dd-yyyy" type="text" id="input1" name="input1"></input>
<span class="add-on">
<i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>
</span>
</div>
</div>

Plunker

关于javascript - Angular js 中的 Twitter Bootstrap 日期选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20966319/

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