我想設置一個表單的密碼。我基本上希望有人在密碼字段中輸入密碼並點擊提交,如果密碼正確,它會將它們重定向到同一個窗口中的buybutton.php。如果密碼不正確,會彈出一個JavaScript警告,提示'密碼錯誤'。我試着寫出Javascript,但點擊按鈕時沒有動作發生。我在下面的代碼中做了什麼錯誤?謝謝您的幫助!Javascript密碼提交 - 表格
<!DOCTYPE html>
<body width="950" height="300" style="background-image:url('giftcard_bg.jpg');">
<head>
<SCRIPT LANGUAGE="JavaScript">
function goForit() {
var passwd;
passwd = this.document.giftForm.pass.value;
if(passwd=="samsamsam"){
window.open ('buybutton.php','_self',false)
}
else{
alert('Password wrong');
}
}
</SCRIPT>
</head>
<div style="position:absolute; top:150px; left:285px; text-align:center;">
<form id="giftForm">
<input type="password" id="pass" placeholder="Enter Secret Code" style="font-size:150%;"/>
<br />
<input type="button" onClick="goForit()" value="Submit" style="font-size:150%; margin-top:15px;" />
</form>
</div>
</body>
</html>
希望你不依賴於任何真正的安全。 – j08691 2012-08-16 17:20:34
僅供參考,HTML無效:它是'
'。你不應該在''內嵌入''。 – JJJ 2012-08-16 17:28:26是啊@ j08691,它不一定是一個超級安全的東西,它只是一個有趣的小促銷,我們正在運行,所以如果他們看到密碼並不是什麼大事。哈哈,這絕對不會對那個有效... – MillerMedia 2012-08-16 19:40:59