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>.

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度