我创建了一个密码保护页面。情况就是这样,当你进入密码保护页面时,它会询问你的密码,当你输入正确的密码时,如果没有,内容会显示,它仍会再次要求正确的密码。在我的情况下,即使我输入正确的密码,它仍然在寻找正确的密码。
虽然我已经意识到自己的错误,但我仍然不知道如何纠正错误。我犯的错误是,我的提交按钮中只有一个功能,所以如果显示访问被拒绝表单中的提交按钮,它仍然会回到原始状态。
有人可以帮助这个。非常感谢你提前。
<script>
function password(){
var password = document.getElementById('pw').value;
if (password==123456){
document.getElementById('1354423021').style.display = 'block';
document.getElementById('1066133308').style.display = 'none';
}
else
{
document.getElementById('1551787368').style.display = 'block';
document.getElementById('1066133308').style.display = 'none';
}
}
HTML
<div dm:templateorder="1" class="dmDefaultRespTmpl" id="1811148618">
<div class="innerPageTmplBox dmDefaultPage dmRespRowsWrapper dmRespRowsWrapperSize1" id="1536984083" style="min-height: 362px;">
<div class="dmRespRow dmReadySection" dm:templateid="ContactUs" id="1827814270">
<div class="dmRespColsWrapper ContactUsSection" id="1299906644">
<div class="dmRespCol small-12 medium-12 large-12" id="1039282650">
<!-- *** INSERT YOUR HTML BELOW *** -->
<div class="dmform default dmContactDefaultForm" preserve_css="true" dmle_widget="dudaContactUsRespId" id="1695446506">
<h3 class="dmform-title dmwidget-title" id="1231366131" hide="false">
Sample Password Protect
</h3>
<div class="dmform-wrapper" preserve_css="true" id="1072124085">
<form method="post" class="dmRespDesignRow" locale="ENGLISH" id="1066133308">
<div class="dmforminput required small-12 medium-4 large-4 dmRespDesignCol" id="1525691246">
<label for="dmform-0" id="1160733053">
Enter password to view content:
</label>
<input type="password" name="dmform-0" style="margin-left: 20px;" id="1410499183"/>
<input type="hidden" name="label-dmform-0" value="Name" id="1625837675"/>
</div>
<div style="float:left; width: 150px;" class="dmformsubmit dmWidget R" preserve_css="true" id="1382804230">
<input class="" name="submit" type="submit" value="Submit" id="1532566041" onclick="password()"/>
</div>
</form>
</div>
<input name="dmformsendto" type="hidden" value="" preserve_css="true" id="1955950480"/>
<input class="dmActionInput" type="hidden" name="action" value="/_dm/s/rt/widgets/dmform.submit.jsp" id="1702158220"/>
<input name="dmformsubject" type="hidden" value="Form Message" preserve_css="true" id="1329461076"/>
</div>
<div class="dmform default dmContactDefaultForm" preserve_css="true" dmle_widget="dudaContactUsRespId" id="1439487325">
<h3 class="dmform-title dmwidget-title" id="1325046572" hide="true">
</h3>
<div class="dmform-wrapper" preserve_css="true" id="1139343276">
<form method="post" style="display:none;" class="dmRespDesignRow" locale="ENGLISH" id="1551787368">
<div class="dmforminput required small-12 medium-4 large-4 dmRespDesignCol" id="1306176401">
<label for="dmform-0" id="1114107505">
Access Denied
</label>
<input type="password" name="dmform-0" style="margin-left: 20px;" id="pw"/>
<input type="hidden" name="label-dmform-0" value="Enter password to view content" id="1369838574"/>
<label style="color:red;">
Incorrect Password!
<br/>
Please try Again.
</label>
</div>
<div style="float:left; width: 150px;" class="dmformsubmit dmWidget R" preserve_css="true" id="1170923147">
<input class="" name="submit" type="submit" value="Submit" id="1040411433" onclick="password()"/>
</div>
</form>
</div>
<input name="dmformsendto" type="hidden" value="" preserve_css="true" id="1116836665"/>
<input class="dmActionInput" type="hidden" name="action" value="/_dm/s/rt/widgets/dmform.submit.jsp" id="1195111197"/>
<input name="dmformsubject" type="hidden" value="Form Message" preserve_css="true" id="1609194082"/>
</div>
</div>
</div>
</div>
<div class="dmRespRow dmDefaultListContentRow" style="text-align:center; display:none;" id="1354423021">
<div class="dmRespColsWrapper" id="1466630272" style="">
<div class="large-12 medium-12 small-12 dmRespCol" id="1920496987" style="">
<!-- *** INSERT YOUR HTML BELOW *** -->
<div class="dmCustomHtml" id="1788238217" dmle_class="true" dmle_widget="html">
<div style="text-align: left;">
SHOW CONTENT
</div>
</div>
</div>
</div>
</div>
</div>
</div>
答案 0 :(得分:0)
您可以按照这种简单的javascript格式..
<!DOCTYPE html>
<html>
<body>
Password:</br>
<input type="password" id="password">
<button onclick="myFunction()">Submit</button>
<p id="login"></p>
<script>
function myFunction() {
password = document.getElementById("password").value;
if(password == '12345'){
document.getElementById("login").innerHTML = "Success!";
}else{
document.getElementById("login").innerHTML = "Wrong password!";
}
}
</script>
</body>
</html>