javascript - 禁用输入字段 x 天
问题描述
假设我今天提交了我的表单,即 1 月 9 日,那么我希望我的表单文本字段在接下来的一个月内被禁用。这样用户每个月只能更新一次。
<input type="number" min="1" name="month" ng-model="year.month"
class="form-control" required />
解决方案
我认为你使用 AngularJS 我看到了 ng-model。我使用伪代码,将当前月份放入一个变量中,然后在服务中比较用户选择的内容。比较附加布尔结果并放入 ng-disabled 中。
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.isChange = function() {
var now = new Date();
monthNow = now.getMonth();
if ((!$scope.year) || ($scope.year.month != monthNow)) {
$scope.check = false;
} else {
$scope.check = true;
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
<input type="number" min="1" name="month" ng-model="year.month"
class="form-control" required ng-disabled="check" ng-change="isChange()" ng-init="isChange()"/>
</div>
推荐阅读
- wordpress - Wordpress:yoast SEO 的问题
- php - 在 PHP 中调用 API GET 请求后没有响应
- python - 来自谷歌云视觉响应nodejs的非最大抑制
- reactjs - 如何在此处定义 proptypes
- r - 由于另一个数据,如何对向量的元素进行排序?
- java - Java - JProgressBar 不会改变值,而 JLabel 不会改变文本
- python - 在 python Django 中从自定义 gsuit 域安全地发送电子邮件
- javascript - node-cron:等待作业完成执行下一个
- python-3.x - 除了 OSError 错误外,我无法设置异常尝试:使用 python3 在 Exscript 中超时
- laravel - 我正在尝试使用 Laravel 作业类在队列中发送电子邮件,但它只是一直说找不到类