[英]Enable/disable button using javascript
我正在嘗試構建一個簡單的html應用程序,以獲取一些基本的客戶信息並將該信息存儲在數據庫中。 捕獲信息之后,當客戶登錄其個人資料時,他可以看到3個按鈕。
button 1= print
button 2= delete
button 3= edit
特殊要求:
對於下一次后續登錄
到目前為止,我已經做了以下事情:
<html>
<head>
<script>
function enableButton() {
document.getElementById("button2").disabled = false;
document.getElementById("button3").disabled = false;
}
</script>
</head>
<body>
<input type="button" id="button1" value="print" onclick="enableButton()" />
<input type="button" id="button2" value="delete" disabled />
<input type="button" id="button3" value="edit" disabled />
</body>
</html>
但這並不能滿足上述要求。 任何幫助,將不勝感激
使用HTML5 localStorage或Javascript Cookie來滿足要求,因為它完全基於用戶登錄。
您必須遵循的步驟:
通過這樣做,您可以確定哪個是新用戶,哪個是舊用戶,並根據該功能執行功能。
使用localStorage
可能是一種解決方法,因為您沒有描述服務器端會話檢索的任何使用
var trueOnFirstVisit = window.localStorage.firstVisit || "true";
$("#button2, #button3").prop("disabled", trueOnFirstVisit);
window.localStorage.firstVisit = "false";
因此,如果我們的localStorage值為"false"
表示用戶已經訪問了該頁面。
https://developer.mozilla.org/en/docs/Web/API/Window/localStorage
http://api.jquery.com/prop/
假設您已經在用戶登錄時存儲了信息,則可以使用$.cookie('varible_name');
訪問該信息$.cookie('varible_name');
如果您使用過Cookie。
您還可以發送發布請求並使用rpc $ .post(...)並檢查用戶是否登錄。如果后續登錄意味着單獨登錄而不是持久登錄,則可以在數據庫的登錄表中保留一個計數器並根據需要更新/獲取。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.