![](/img/trans.png)
[英]How to enable the button once the user clicked the image using javascript
[英]How to disable a button, if it is clicked once in a day and enable on next day using JavaScript and AngularJS 1?
一旦我在一天中點擊(即)一天一次用戶使用提交按鈕輸入詳細信息,我的按鈕應該被禁用。 第二天應啟用自動按鈕。
幫助我使用JavaScript或AngularJS ..
如果你有后端,你可以在數據庫中保持狀態,因為Sajal說,但既然你在詢問angularjs / javascript和前端解決方案cookie(Chris說的話)或localStorage是什么方法,設置cookie並根據cookie你可以設置按鈕每天重置
關於w3schools的更多信息:
https://www.w3schools.com/js/js_cookies.asp https://www.w3schools.com/html/html5_webstorage.asp
請記住,可以修改cookie,因此如果您需要全面的解決方案,DB是最好的方法。
您可以在本地存儲中保存點擊的狀態,但此解決方案不安全。 您應該添加服務器端控件。
您可以使用超時功能。 您可以給出超時的特定時間,然后在超時后啟用該按鈕。
EX:
var theInterval = $interval(function(){
//Enable button
}.bind(this), time);
您可以使用localStorage :
<button ng-disabled="!buttonIsActive()" ng-click="onClick()"></button>
$scope.buttonIsActive = function() {
var now = new Date();
var day = now.getDate();
var lastClickDay = parseInt(localStorage.getItem("last-click-day"));
return day > lastClickDay;
}
$scope.onClick = function() {
var now = new Date();
var day = now.getDate();
localStorage.setItem("last-click-day", day);
// ... Do something else here
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.