douxuanma4357 2014-03-16 20:36
浏览 36
已采纳

以admin身份登录时显示隐藏的表单(javascript,php)

I have created simple login button,which can only admin log in (only 1 password works).After clicking on a button "LOG IN" it takes me to the new html file.There is a form in this new html file that is hidden but I want it to be visible when i enter it with login.So I was thinking about document.getElementById("hidden_form").style.display = "block"; but that form is not in that HTML file so that cant work.

This is the javascript of the button (so when i click on it it opens a new html document)

<input type="password" id="password" /><br />
<input class="orangebutton" type="submit" value="Nastavi" 
onclick="if (document.getElementById('password').value == 'password')
 location.href='index.html'; else alert('Wrong password!');
" />

And this is the form that is hidden in index.html:

 <form class="echo" id="form" style="display:none">

So I want it to change from display:none to display:block when I get redirected to the new site.I havent really got any ideas so far, except this one:use javascript to check which was the previous page client went on, and if it was the page of the login then put display:block , but if it isnt then do display:none. Im sure there is some much easier way, but cant think of any at the moment.

  • 写回答

1条回答 默认 最新

  • douqiao6015 2014-03-16 21:19
    关注

    If you want to change something on a new/other page, you should do that in the other page. With javscript you cannot change something that isn't loaded yet.

    Easiest way to do this with javascript would be something like this:

    <script type="text/javascript">
    if (location.search == "?show") {
        document.getElementById("hidden_form").style.display = "block";
    }
    </script>
    

    Note that this script should be executed after the <form> is added to the DOM. So preferably in some document.ready function or in a script block that is placed below the <form>.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端