【问题标题】:Need to create jquery password prompt (should be simple)需要创建jquery密码提示(应该很简单)
【发布时间】:2013-02-24 04:45:57
【问题描述】:

所以我为我托管的寻宝游戏创建了一个网站,但我需要一个密码提示来显示几乎每个页面,以确保他们已经完成了继续前进的挑战。我正在使用 Jquery,让密码提示出现的唯一方法是在我刷新页面之后,这不好。我需要一种将一个页面链接到另一个页面的方法,并在他们看到该页面之前显示密码提示。这是重要的html。另外,如果可以的话。每当我刷新页面时,所有的 CSS 似乎都消失了,我留下了文字。如果你能请帮忙。

    <!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>jQuery</title>
      <link rel="stylesheet" href="../themes/scavenger-hunt.min.css" />
    <link rel="stylesheet" href="../Publish/jquery-mobile/jquery.mobile.structure-1.0.min.css" />
    <script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.3.0-rc.1/jquery.mobile-1.3.0-rc.1.min.js"></script>
  <body> 
<script language="javascript">
var password
var pass1="123"

password=prompt('Please enter password to view page')
if (password==pass1)
alert('password correct! Press ok to continue.')

else{
  window.location="index.html";
  alert('password incorrect! Redirecting')
}

</script>
<div data-role="page" id="home">
  <div data-role="header">
    <h1>Hint 1</h1>

  </div>

【问题讨论】:

  • 这需要有多安全?因为如果我在你的寻宝游戏中,我会在十秒内绕过你的密码验证并获胜。
  • 我没有看到 jquery 代码。
  • @mrtsherman 它不必那么安全,加上它的移动设备,所以它有点难以绕过。
  • @Dave Jquery 如下。我只是说它的 jquery,因为这可能是问题的一部分。如果你愿意,我可以显示整个页面

标签: javascript jquery html password-protection


【解决方案1】:

有几种方法可以解决这个问题,但这里有两种。一个比另一个容易。我这样做的第一种方法是将所有内容都放在页面上,但在页面加载时将其隐藏。如果密码输入正确,则会显示该页面。

body { display:none; }

if (password == pass1) { $('body').show(); }

http://jsfiddle.net/5JyTy/

另一种是使用 AJAX,仅在密码正确时才请求/显示内容。

if (password == pass1) { $('body').load('ajax/test.html'); }

【讨论】:

  • 不是这样,虽然这确实有点帮助。问题似乎是页面的加载方式。该页面使用 ajax 加载器加载(换句话说,它以不同方式加载)。我正在使用带有主题的 Jquery 手机。当我尝试在没有主题的网页上加载它时,它可以完美运行。如果有帮助的话,这里是网站(点击提示 1 然后刷新)sh.atwebpages.com/team1/home.html。非常感谢
【解决方案2】:

你可以使用ajax调用和jquery msg插件,很好很简单

http://dreamerslab.com/blog/en/jquery-blockui-alternative-with-jquery-msg-plugin/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多