在AngularJS中,如何防止选中的选项和文本框在按下F5键后被清除,直到按钮被点击
How to prevent a selected option and a textbox from being cleared after pressing F5 In AngularJS, until a button is clicked
我有一个选择选项和一个文本框,当用户选择一个选项并在文本框中输入文本,数据被保存在sql数据库中。我需要知道如何防止选中的选项和当用户按下F5键时,文本框中的文本不会被清除,直到在AngularJS中单击某个按钮,然后select选项和文本框才会被清除。这是我试过的,但它不起作用。
JS
function Model($http) {
var self = this;
self.$http = $http;
var CurrentDowntimeEvent = {};
self.StartDowntimeEvent = function () {
var params= {
DepartmentId:self.LineId
, EventId: self.CurrentDowntimeEvent.EventId
, CategoryId: self.CurrentDowntimeEvent.CategoryId
, StartTime: self.CurrentDowntimeEvent.startTime
, Comment: self.CurrentDowntimeEvent.Comment
};
Hesto.Ajax.ngget(self.$http, ADD_DOWNTIME_START, params, function (data) {
self.CurrentDowntimeEvent = data.data[0];
console.log(self.CurrentDowntimeEvent);
});
}
angular.module('myApp', [])
.controller('DowntimeController', function ($scope, $http) {
$scope.Model = new Model($http);
});
The CategoryId is the select option and the Comment is the textbox.
HTML <select class="categories" ng-disabled="selectlistdisabled" ng-model="Model.CurrentDowntimeEvent.CategoryId" ng-click="display()">
<option value= {{downtimeCategory.CategoryId}} ng-repeat="downtimeCategory in Model.DowntimeCategories">{{downtimeCategory.CategoryName}}</option>
</select>
<button ng-click="Model.StartDowntimeEvent()">Start Downtime Event</button>
<button ng-click="Model.StopDowntime()">Stop Downtime Event</button>
我选择localStorage - link。
基本上,你是保存js对象在浏览器中的字符串,所以你可以得到的数据,只要你想要的,即使在10000刷新或5个月。这是存储这些类型数据的更优雅的方式,而不是cookie
数据以名称/值对的形式存储,网页只能访问自行存储的数据。
与cookie不同,存储限制要大得多(至少5MB)信息永远不会传输到服务器。
相关文章:
- 清除按钮提交后的文本区域
- HTML5画布创建“清除画布”按钮的正确方法
- 清除按钮不适用于我的javascript和hmtl5画布
- 输入文本区域的清除按钮
- 如何使用javascript刷新我的html页面时清除按钮单击
- 单击按钮清除推送通知
- jQuery移动列表过滤:如何更改清除按钮文本
- 计算器清除按钮
- 为什么清除按钮不从购物车中删除价格
- JavaScript计算器问题与清除按钮
- 在输入框中输入数据时显示清除按钮.当输入没有聚焦且输入框中没有数据时,隐藏清除按钮
- 清除按钮点击时的jQuery验证
- 文本区域应该得到复制到另一个文本区域和原始文本区域应该清除按钮点击使用javascript
- 文本从一个文本区域应该得到复制到另一个文本区域和原始文本区域应该清除按钮点击使用javascript
- 随时日期选择器添加一个清除按钮
- 如何在单个文本框中添加多个联系号码,以及使用javascript添加的每个文本的X(清除)按钮
- 如何刷新过滤搜索时的“清除”按钮;在文本的边缘点击
- 当试图清除按钮输入时,Form.elements.filter不是一个函数
- 隐藏'清除'按钮,直到'按钮点击
- 如何使用jquery为每个值动态添加清除按钮