這當然不是最安全的方法,但我只有 html 和 javascript,所以這是我能想到的最好的方法。我構建了一些示例代碼來展示它應該如何作業,但它不起作用!
密碼應該每天更改,使人們更難猜測它們。用戶獲取密碼的方式將是通過 google docs 發送的 html 檔案并手動批準對其進行訪問。javascript 將在顯示密碼的檔案上多次混淆。還會有密碼查看密碼。我已經弄亂了這段代碼好幾天了,什么都沒有......
window.onload = function() {
chgDailyImg();
document.getElementById('answer').innerHTML = imagearray[i]
}
var passwordInput = prompt("Please enter the password to continue...");
const imagearray = new Array();
imagearray[0] = "9G7DcwnWafg*EtMH";
imagearray[1] = "MDe^5qHTG#P9dHBm";
imagearray[2] = "h%$u@2Nfu8FL9H R";
imagearray[3] = "X&NB5tYdUs5u@G#z";
imagearray[4] = "k#Rc3LGsCdu4q%qZ";
imagearray[5] = "!$p!Ss5BA%#4zeAa";
imagearray[6] = "qz63!tue3WCUxJ@R";
let i = 0;
function chgDailyImg() {
let d = new Date();
i = d.getDay();
}
if ((passwordInput, imagearray[i]) === true) {
document.getElementById('hiddenContent').style.visibility = "visible"
console.log("RIGHT")
} else {
document.getElementById('hiddenContent').style.visibility = "hidden"
console.log("WRONG")
}
<h1 id="hiddenContent" style="visiblity: hidden">Hidden Stuff That Requires Password To See!</h1>
uj5u.com熱心網友回復:
你是不是檢查,看是否passwordInput是imagearray正確的。
要檢查密碼是否在陣列中,請使用(imagearray.indexOf(passwordInput) !== -1).
查看檢查元素是否在陣列中的其他方法:如何檢查陣列是否包含 JavaScript 中的值?
window.onload = function() {
chgDailyImg();
document.getElementById('answer').innerHTML = imagearray[i]
}
var passwordInput = prompt("Please enter the password to continue...").trim();
const imagearray = new Array();
imagearray[0] = "9G7DcwnWafg*EtMH";
imagearray[1] = "MDe^5qHTG#P9dHBm";
imagearray[2] = "h%$u@2Nfu8FL9H R";
imagearray[3] = "X&NB5tYdUs5u@G#z";
imagearray[4] = "k#Rc3LGsCdu4q%qZ";
imagearray[5] = "!$p!Ss5BA%#4zeAa";
imagearray[6] = "qz63!tue3WCUxJ@R";
let i = 0;
function chgDailyImg() {
let d = new Date();
i = d.getDay();
}
if (imagearray.indexOf(passwordInput) !== -1) {
document.getElementById('hiddenContent').style.visibility = "visible"
console.log("RIGHT")
} else {
document.getElementById('hiddenContent').style.visibility = "hidden"
console.log("WRONG")
}
<h1 id="hiddenContent" style="visiblity: hidden">Hidden Stuff That Requires Password To See!</h1>
<div id="answer"></div>
uj5u.com熱心網友回復:
在對 indexOf 做了更多研究之后,我確定這不是我所需要的。我利用Chris Happy 的代碼來創建這個作業代碼。
<h1 id="hiddenContent" style="visiblity: ">Hidden Stuff That Requires Password To See!</h1>
<div id="answer"></div>
<script type="text/javascript">
window.onload = function() {
chgDailyImg();
validate();
document.getElementById('answer').innerHTML = imagearray[b]
}
var passwordInput = prompt("Please enter the password to continue...");
const imagearray = new Array();
imagearray[0] = "9G7DcwnWafg*EtMH";
imagearray[1] = "MDe^5qHTG#P9dHBm";
imagearray[2] = "h%$u@2Nfu8FL9H R";
imagearray[3] = "X&NB5tYdUs5u@G#z";
imagearray[4] = "k#Rc3LGsCdu4q%qZ";
imagearray[5] = "!$p!Ss5BA%#4zeAa";
imagearray[6] = "qz63!tue3WCUxJ@R";
let b = 0;
function chgDailyImg() {
let d = new Date(); /*** create a date object for use ***/
b = d.getDay();
}
function validate() {
if (passwordInput == imagearray[b]) {
console.log("RIGHT")
document.getElementById('hiddenContent').style.visibility = "visible"
} else {
document.getElementById('hiddenContent').style.visibility = "hidden"
console.log("WRONG")
}
}
</script>
我對這段代碼的理解是,當passwordInput等于imagearray[b]([b]等于 0 直到chgDailyImg()在頁面加載時運行然后[b]等于星期幾)時,它將顯示hiddenContent. 在 時window.onload,提示使用 來檢查提供的密碼是否等于imagearray[b](今天的密碼)function validate() if (passwordInput == imagearray[b]) console.log("RIGHT"),然后validate()在加載頁面時宣告該函式 。
我最初詢問的答案比我預期的要簡單得多。一個月前才開始學習JavaScript,當時我提出的問題聽起來很難,但現在我知道了提示是如何運作的,我有了更好的理解。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/380848.html
標籤:javascript html 数组 功能 表现
