Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
正在尝试使用javascript在我的页面上创建javascript帐户系统。。。但显然我';我忽略了什么_Javascript_Jquery_Html_Local Storage_Account - Fatal编程技术网

正在尝试使用javascript在我的页面上创建javascript帐户系统。。。但显然我';我忽略了什么

正在尝试使用javascript在我的页面上创建javascript帐户系统。。。但显然我';我忽略了什么,javascript,jquery,html,local-storage,account,Javascript,Jquery,Html,Local Storage,Account,我的html页面似乎忽略了脚本的一部分:当您有帐户时,它不会隐藏#signupdiv,当您没有帐户时,它不会隐藏#accountdiv:下面是JavaScript代码: if(localStorage.hasAnAccount){ $('#signup').hide(); $('#AccountName').html(localStorage.accountName) }else{ $('#account').hide(); } function createNewAcc

我的html页面似乎忽略了脚本的一部分:当您有帐户时,它不会隐藏
#signup
div,当您没有帐户时,它不会隐藏
#account
div:下面是JavaScript代码:

if(localStorage.hasAnAccount){
    $('#signup').hide();
    $('#AccountName').html(localStorage.accountName)
}else{
    $('#account').hide();
}
function createNewAccount(){
    localStorage.accountName=$('#newAccountName').html();
    localStorage.accountPassword=$('newAccountPassword').html();
    if(typeof localStorage.accountName=='string'&& typeof localStorage.accountPassword=='string'){
        alert('congrats! Your account has been made!');
        localStorage.hasAnAccount=true;
    }else{
        alert('check that your name and password are alphanumeric strings');
    }
}
下面是HTML代码:

<html>
    <head>
        <title>Account | Cicada3301's Website</title>
     <link rel='stylesheet' type='text/css' href='http://www.copot.eu/matei/assets/stylesheet.css'>
  <link rel='stylesheet' href='http://www.copot.eu/matei/assets/jquery-ui-stylesheet.css'>
  <script  type="text/javascript" src="http://www.copot.eu/matei/assets/jquery-1.10.2.min.js"></script>
  <script src="http://www.copot.eu/matei/assets/jquery-ui.js"></script>
    <script type="text/javascript" src="http://www.copot.eu/matei/assets/scripts.js"></script>
    <script type='text/javascript' src='http://www.copot.eu/matei/account/account-scripts.js'></script>
    <link rel='shortcut icon' type='image/x-icon' href='http://www.copot.eu/matei/assets/me.jpg'>
    </head>
    <body> 
        <div id='account'>
            <div id='AccountName'></div>
        </div>
        <div id='signup'>
            <p><input type='text' id='newAccountName'> Insert your account name</p>
            <p><input type='text' id='newAccountPassword'> Insert your account password</p>
            <p><input type='button' onclick='createNewAccount()' value='Create Account'></p>
        </div>
    </body>
</html>
我发现它:

首先,我建议您避免内联javascript事件

替换此行:

您的“bug”与输入:文本字段中的数据类型有关。将它们替换为
.val()
,而不是
.html()

还有一场比赛

仅提及:

  • 您必须在JSFIDLE上重新运行脚本才能看到它的应用
  • 页面上有javascript错误(ReferenceError:barHeight未定义 来源:第33行)witch阻止脚本的其余部分

将脚本包装在
document.ready中
@Mathew Nope,仍然不起作用(网页仍然是一样的…但是在$(document.ready(function(){script})中敲击脚本)@Milkywayspatterns它运行警报:Ichecked@Sudhir是的,它是:我相信你可以检查脚本在,所以我应该改变以及按钮id到createNewAccount的权利?不应该把它写在文件里,写。。。让我试试。。。顺便说一句,本地存储是服务器端还是客户端?对不起。。。不工作:我在网站上加载了文件:你可以自己检查!提供的jsiddle工作正常。看看JSFIDLE的左栏,脚本被包装在DOMready中。奇怪的是:在我的屏幕上不起作用,如果没有帐户,不隐藏#帐户,并且不隐藏#在应该有帐户时注册。。。你确定吗?祝你网站的其他部分好运Matei Copot,我能为你做的一切,这个问题写在我的答案中。如果仔细阅读,您会注意到我在您的站点上标记了一个javascript错误,干扰了它的行为。
    $(document).ready(function(){
if (localStorage.hasAnAccount) {
    $('#signup').hide();
    $('#AccountName').html(localStorage.accountName)
} else {
    $('#account').hide();
}

$('#createNewAccount').click(

function () {
    if (typeof localStorage.accountName == 'string' && typeof localStorage.accountPassword == 'string') {
        localStorage.accountName = $('#newAccountName').val();
        localStorage.accountPassword = $('newAccountPassword').val();

        alert('congrats! Your account has been made!');
        localStorage.hasAnAccount = true;
    } else {
        alert('check that your name and password are alphanumeric strings');
    }
});
})
if (localStorage.hasAnAccount) {
    $('#signup').hide();
    $('#AccountName').html(localStorage.accountName)
} else {
    $('#account').hide();
}


/* run your fonctionnality upon the id of your button */
$('#createNewAccount').click(

function () {
    /* replace .html() by .val() */
        localStorage.accountName = $('#newAccountName').val();
    /* replace .html() by .val() */
        localStorage.accountPassword = $('newAccountPassword').val();

    /* this next testing will not validate for alphanumeric */
    if (typeof localStorage.accountName == 'string' && typeof localStorage.accountPassword == 'string') {

        alert('congrats! Your account has been made!');
        localStorage.hasAnAccount = true;
    } else {
        alert('check that your name and password are alphanumeric strings');
    }
});