Jquery移动版和PHP页头会在下一页打破按钮


jquery mobile and php headers break buttons on next page

我正在制作一个登录php文件,它使用头来重定向不同类型的用户,当它将用户重定向到他们的特定页面时,页面上的按钮变得不可点击。你能帮我吗?

登录HTML:

 <form action="login-all.php" method="POST">
         <lable>Login:</lable>
         <input type="text" id="name" name="name" placeholder="First Name"/>
         <input type="password" id="pass" placeholder="Password" name="pass"/>
         <button type="submit">Log-In</button>
 </form>
PHP:

if($role === '1' ) { //1 admin - 0 user
          header('Location: admin.php');
          //echo "admin";
      }else{
          header('Location: user.php');
          //echo "user";
      }

User.php上的按钮(不能从header重定向)

 <a href="#input"><button>Input</button></a>
 <a href="#submit"><button>Submit</button></a>

用锚标记包裹按钮不起作用(参见:http://jsbin.com/ekozud/1/)。相反,您需要使用javascript为每个按钮的单击事件添加事件侦听器:

 <button id="google">Go to Google</button>
 <script>
 function goToGoogle() {
     document.location = 'http://www.google.com';
 }
 if(document.addEventListener) {
     document.getElementById('google').addEventListener('click', goToGoogle);
 } else {
     document.getElementById('google').attachEvent('onclick', goToGoogle);
 }
 </script>

当然,这种方法的问题是,如果客户端没有js(或没有启用),这些按钮将无法工作。我建议使用一个没有按钮的锚,并将链接样式化成按钮(如果你真的需要按钮的外观)。