- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要使用 angular javascript 的自定义时间选择器
我在普通下拉框中尝试了时间,看起来不太好因为用户必须选择 3 个下拉菜单1) 小时 2) 分钟 3) 子午线
<select type="text" ng-model="hours">
<option value="00">00</option>
<option value="01">01</option>
</select>
<select type="text" ng-model="minutes">
<option value="00">00</option>
<option value="10">10</option>
</select>
<select type="text" ng-model="meridian">
<option value="AM">AM</option>
<option value="PM">PM</option>
</select>
我打算添加一个时间选择器而不是三个字段
最佳答案
我使用 angular js 为 timepicker 写了一个指令
<!DOCTYPE html>
<html>
<head>
<style>
td.hours {
width: 110px;
}
td.hours div {
display: inline-block;
padding: 5px;
}
</style>
</head>
<body>
<h2>TimePicker Example</h2>
<form ng-app="test" name="myForm" ng-controller="TestController" novalidate>
<p>Time:
<br>
<timepicker></timepicker>
</p>
<br/>
<button ng-click="submit()">Submit</button>
</form>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular-route.min.js"></script>
<script>
var module = angular.module('test', ['ngRoute']).controller("TestController", TestController);
function TestController($scope) {
$scope.submit = function() {
alert($scope.timeValue);
};
}
//Template for the time picker, no CSS, pure HTML. The time-picker tag will be replaced by this
var timePickerTemplate = [
'<div class="timePicker">',
'<label ng-click="toggleTimePicker()">',
'<input type="text" ng-model="timeLabel" ng-bind="timeValue" disabled>',
'</label>',
'<div class="cal-wraper shadow" ng-show="selecting">',
'<table>',
'<tr class="navigation">',
'<tr class="time">',
'<td class="mer"><div ng-click="selectMeridian(meridian)" ng-repeat="meridian in meridians" ng-bind="meridian"></div></td>',
'<td class="hours"><div ng-click="selectHour(hour)" ng-repeat="hour in hours" ng-bind="hour.label"></div></td>',
'<td class="minutes"><div ng-click="selectMinute(minute)" ng-repeat="minute in minutes" ng-bind="minute"></div></td>',
'</tr>',
'</table>',
'</div>',
'</div>'
].join('\n');
module.directive("timepicker", function() {
return {
restrict: 'E',
templateUrl: "timePicker.tmpl",
transclude: true,
controller: function($scope) {
var timeObj = {
AM: [],
PM: []
};
for (var i = 0; i <= 11; i++) {
timeObj.AM.push({
label: (i < 10 ? '0' + i : i),
value: i
});
}
timeObj.PM.push({
label: 12,
value: 12
});
for (var i = 1; i <= 11; i++) {
timeObj.PM.push({
label: (i < 10 ? '0' + i : i),
value: i + 12
});
}
$scope.meridians = ["AM", "PM"];
$scope.hours = timeObj.AM;
$scope.minutes = ["00", "15", "30", "45"];
if ($scope.timeValue == undefined) {
$scope.timeValue = 9 * 60 * 60 * 1000;
}
$scope.toggleTimePicker = function() {
$scope.selecting = !$scope.selecting;
};
$scope.$watch('timeValue', function(val) {
$scope.updateLabel(val);
});
$scope.selectMeridian = function(meridian) {
$scope.hours = timeObj[meridian];
$scope.timeValue = (meridian == "AM" ? (9 * 60 * 60 * 1000) : (15 * 60 * 60 * 1000));
};
$scope.selectHour = function(hour) {
$scope.timeValue = (hour.value * 60 * 60 * 1000);
};
$scope.selectMinute = function(minute) {
var time = $scope.timeValue;
var mts = time % (60 * 60 * 1000);
$scope.timeValue = (time - mts + minute * 60 * 1000);
};
$scope.updateLabel = function(timeValue) {
var mts = timeValue % (60 * 60 * 1000);
var hrs = (timeValue - mts) / (60 * 60 * 1000);
var mts2 = mts / (60 * 1000);
var mer = (hrs < 11) ? "AM" : "PM";
var hrs2 = (hrs > 12) ? hrs - 12 : hrs;
$scope.timeLabel = (hrs2 < 10 ? '0' + hrs2 : hrs2) + ":" + (mts2 == 0 ? '00' : mts2) + " " + mer;
};
}
}
}).run([
'$templateCache',
function($templateCache) {
$templateCache.put('timePicker.tmpl', timePickerTemplate); // This saves the html template we declared before in the $templateCache
}
]);
</script>
</body>
</html>
关于angularjs-directive - 使用 Angular js 自定义时间选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25971845/
在JSON输出中,“步骤”中有一个字段“maneuver”。在此“向左转”,“向右转”,“向左转轻微”等。示例为here 在哪里可以找到“操纵”字段的定义以及可能的值列表?没有相关描述here 提前致
默认情况下,我们如何从Google Direction API建议的替代 route 获得从A点到B点的最短距离路线?默认情况下,它会根据当前交通状况为我们提供最短持续时间的路线。我已经注意到,如果您
我想知道“precompile(r) directive”和“preprocessor directive”是一回事吗?我对前者不熟悉,但只是听说过,并通过这个Google在互联网上找到了一些关于它的
对于我的项目,我目前正在开发自定义表单/输入指令。 例如,我有以下指令: angular.module('myApp').directive("textField", function() {
我用谷歌搜索了一下,但找不到任何详细说明如何制作动态包装内容的 Angular 指令的内容(例如 http://demos.telerik.com/kendo-ui/panelbar/angular
我正在尝试在另一个指令中使用一个指令。具体来说,我有一个模态指令,我想传递一个表单指令,并将充当模态的主体。 我的模态指令: angular.module('Storyboard').dir
我构建了一个模块化形式的小型演示,其中包含单独的输入指令。它还可以预览绑定(bind)到相同 Controller 和范围的表单值。 导致问题的输入指令是嵌入到表单内的输入:
HTML 指令 .directive('authorname', function() { return { restrict: 'E', scope: {
我有可以编译的 Angular 指令 至和 至Hello World! 我怎样才能把greeting在我的 HTML 中标记并将其编译为 print-greeting然后最后显示Hello World
标题中引用的脚注是什么意思?这是 6.10.3p11 的脚注 If there are sequences of preprocessing tokens within the list of arg
因此,电话号码始终是 ltr(从左到右)。 在多语言网站上工作,我需要在方向为 rtl 的文本段落中插入一个电话号码(带有“+”前缀和由“-”分隔的数字)(当然是针对相关语言) 所以我有这样的东西:
我有一个标题元素,我想显示 flex 列,这样我就可以将 .container div 垂直居中。这工作正常。然后我需要 .container 中的元素在 1200px 之间以均匀的间距连续 flex
如何将整个ng-repeat对象传递给指令(或如何将指令的作用域设置为ng-repeat项)? 我是新来的有角度的人,很难解决这个问题。 我有一个 Controller ,可以很好地呈现以下内容:
我需要将“...”放在文本前面,并在填充 div 时仅显示文本的最后一部分。 正常时不执行任何操作 C:\fakepath\996571_1398802860346752_209456547
我需要将“...”放在文本的前面,并且只显示它的最后一部分,当它填充 div 时。 正常的时候什么也不做 C:\fakepath\996571_1398802860346752_209456
我需要一个“粘性”指令,当它位于页面顶部时向元素添加一个 css 类,并且还指示其状态的变化。出于这个原因,我定义了一个范围,如 { onStickyChange: '&' }。现在我想在 angul
我对 ngSwitch 指令有点困惑——它是“属性指令”还是“结构指令”。 属性指令用“方括号”编写,如 [ngStyle]、[ngClass] 等(我们将其写为 [ngSwitch],将其称为“属性
Wi-Fi direct 的 Wiki 规范声称“只有一个 Wi-Fi 设备需要兼容 Wi-Fi Direct 才能建立点对点连接,在彼此之间直接传输数据,大大减少了设置”。但是从 android A
我有一个响应式模板,我正尝试将其与我的 Angularjs 应用程序一起使用。这也是我的第一个 Angular 应用程序,所以我知道我在未来有很多错误和重构。 我已经阅读了足够多的关于 Angular
首先,我这样做的方式可能不正确。但我会解释这个问题: 1) 我正在创建名为 的指令 2) 当点击第一个指令中的按钮时,我试图在运行时动态插入第二个指令 如下: var app = angu
我是一名优秀的程序员,十分优秀!