菜鸟教程小白 发表于 2022-12-12 14:52:41

ios - 在 Cordova 中使用 Button 进行登录验证后重定向


                                            <p><p>我是 Cordova 语言的初学者。我正在尝试在 javascript 中单击按钮时重定向我的 html 页面。在 <code>validateform</code> 方法中,我想重定向到我的主页。我已经尝试了所有可能的东西,例如 <code>window.location</code>, <code>document.location</code> 。但我没有得到重定向的确切答案。 </p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;script type=&#34;text/javascript&#34;&gt;
      window.onload = function()
      {
            document.addEventListener(&#34;deviceready&#34;, init, false);
      }

    function init()
    {
      var myButton = document.getElementById(&#34;BtnClick&#34;);
      myButton.addEventListener(&#34;click&#34;, validateform, false);
    }

    function validateform()
    {
      var myButton = document.getElementById(&#34;BtnClick&#34;);
      var user = document.getElementById(&#34;username&#34;).value;
      var paswd = document.getElementById(&#34;password&#34;).value;
      var reg = /^()+\@()+\.({2,4})$/;

      if (user == &#34;&#34;) {
            alert(&#34;Name must be filled out&#34;);
            return false;
      } else if (reg.test(user) == false) {
            alert(&#34;Invalid Email Address&#34;);
            return false;
      } elseif (paswd == &#34;&#34;) {
            alert(&#34;Password must be filled out&#34;);
            return false;
      } else {
            alert(&#34;TRY!&#34;);
            document.location = &#34;home.html&#34;;
            return false;
      }
    }
      &lt;/script&gt;

    &lt;meta http-equiv=&#34;Content-Security-Policy&#34; content=&#34;default-src &#39;self&#39; data: gap: https://ssl.gstatic.com &#39;unsafe-eval&#39;; style-src &#39;self&#39; &#39;unsafe-inline&#39;; media-src *; img-src &#39;self&#39; data: content:;&#34;&gt;
      &lt;meta name=&#34;format-detection&#34; content=&#34;telephone=no&#34;&gt;
            &lt;meta name=&#34;msapplication-tap-highlight&#34; content=&#34;no&#34;&gt;
                &lt;meta name=&#34;viewport&#34; content=&#34;user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width&#34;&gt;
                  &lt;link rel=&#34;stylesheet&#34; type=&#34;text/css&#34; href=&#34;css/index.css&#34;&gt;
                        &lt;/head&gt;

&lt;body&gt;
    &lt;form id=&#34;loginForm&#34; class = &#34;centered&#34; &gt;
      &lt;div class=&#34;middle&#34;&gt;
            &lt;img src = &#34;img/newlogo.png&#34; width=&#34;150&#34; height=&#34;150&#34;/&gt;
      &lt;/div&gt;

      &lt;div data-role=&#34;fieldcontain&#34;&gt;
            &lt;input type=&#34;email&#34; name=&#34;username&#34; id=&#34;username&#34; value=&#34;[email protected]&#34; placeholder=&#34;Username&#34; class=&#34;middle textfield&#34;/&gt;
      &lt;/div&gt;

      &lt;div data-role=&#34;fieldcontain&#34; &gt;
            &lt;input type=&#34;password&#34; name=&#34;password&#34; id=&#34;password&#34; value=&#34;789456&#34; placeholder=&#34;Password&#34; class=&#34;middle textfield&#34; maxlength=&#34;10&#34;/&gt;
      &lt;/div&gt;

      &lt;div class = &#34;middle&#34;&gt;
            &lt;button id = &#34;BtnClick&#34; class = &#34;button&#34; &gt;Submit&lt;/button&gt;
      &lt;/div&gt;
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>感谢大家的帮助!我找到了解决方案:</p>

<p>在<code>index.html</code></p>

<pre><code>&lt;div class = &#34;loginButton&#34;&gt;
      &lt;a id = &#34;BtnClick&#34;&gt;Submit&lt;/a&gt;
&lt;/div&gt;
</code></pre>

<p>在<code>validateform</code>方法中:</p>

<pre><code>window.location.href = &#34;home.html&#34;;
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 在 Cordova 中使用 Button 进行登录验证后重定向,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/52420959/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/52420959/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 在 Cordova 中使用 Button 进行登录验证后重定向