“password and re-typed password” verification 后继续前进

huangapple go评论58阅读模式
英文:

Moving on after "password and re-typed password" verification

问题

I am writing an application on “password and re-typed password” verifying routine.

After the [submit] of the necessary details, the function “check_Password(form)” is activated.

If (not …) then {…}.

If (true), {show “ok” via window.alert() with a ‘true’ returned value.}

Then, I want to move on to the next stage by saying

<a href="mainmenu.html" onClick="checkPassword()">Move on to the next stage</a>

However, the last statement is always on even before the test. How can I hide it and show it only when the verification is ok.


[Added]

<script>
		function myFunction() 
            {location.replace("http://.../index.html")}
</script>
<button onClick="myFunction()">Re-direction</button>```

<details>
<summary>英文:</summary>

I am writing an application on “password and re-typed password” verifying routine.

After the [submit] of the necessary details, the function “check_Password(form)” is activated. 

If (not …) then {…}.

If (true), {show “ok” via window.alert() with a ‘true’ returned value.}

Then, I want to move on to the next stage by saying
 
```&lt;a href=&quot;mainmenu.html&quot; onClick=&quot;checkPassword()&quot;&gt;Move on the next stage&lt;/a&gt;```

However, the last statement is always on even before the test. How can I hide it and show it only when the verification is ok.


----------
[Added]

<script>
function myFunction()
{location.replace("http://.../index.html")}
</script>
<button onClick="myFunction()">Re-direction</button>```

答案1

得分: 1

我认为要解决这个问题,你可以初始隐藏锚点标签,然后根据验证过程的成功或失败来动态触发它,就像这样:

Html:

<!-- 为语句添加占位符元素 -->
<div id="next-stage" style="display: none;">
  <a href="mainmenu.html">继续下一阶段</a>
</div>

<!-- 添加一个按钮来触发密码验证 -->
<button onclick="checkPassword()">提交</button>

JavaScript:

就函数方面而言,考虑到你已经有了验证密码完整性的逻辑,你可以像这样做:

注意: 请记住,我为了测试下面的代码片段,硬编码了密码验证,你可能需要根据用例编写自己的逻辑。

function checkPassword() {
  // 执行密码验证
  var isPasswordValid = true; // 这里是你的密码验证逻辑

  if (isPasswordValid) {
    // 显示下一阶段的语句
    document.getElementById("next-stage").style.display = "block";
    window.alert("密码验证成功!");
  } else {
    window.alert("密码验证失败!");
  }
}

希望这对你有所帮助。

英文:

I think to resolve this issue what you can do is initially hide the anchor tag and dynamically trigger it based on your verification process success or failure like this:

Html:

&lt;!-- Add a placeholder element for the statement --&gt;
&lt;div id=&quot;next-stage&quot; style=&quot;display: none;&quot;&gt;
  &lt;a href=&quot;mainmenu.html&quot;&gt;Move on to the next stage&lt;/a&gt;
&lt;/div&gt;

&lt;!-- Add a button to trigger the password verification --&gt;
&lt;button onclick=&quot;checkPassword()&quot;&gt;Submit&lt;/button&gt;

JavaScript:
On the function side of things given that you already have the logic to verify the integrity of the password, you can do something like this:

Note: Just keep in mind that the password verification is hardcoded by me to test the logic in the below snippet, u might need to write your own logic based on the use case.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

function checkPassword() {
  // Perform the password verification
  var isPasswordValid =true // Your password verification logic here

  if (isPasswordValid) {
    // Show the next stage statement
    document.getElementById(&quot;next-stage&quot;).style.display = &quot;block&quot;;
    window.alert(&quot;Password verification successful!&quot;);
  } else {
    window.alert(&quot;Password verification failed!&quot;);
  }
}

<!-- language: lang-html -->

&lt;!-- Add a placeholder element for the statement --&gt;
&lt;div id=&quot;next-stage&quot; style=&quot;display: none;&quot;&gt;
  &lt;a href=&quot;mainmenu.html&quot;&gt;Move on to the next stage&lt;/a&gt;
&lt;/div&gt;

&lt;!-- Add a button to trigger the password verification --&gt;
&lt;button onclick=&quot;checkPassword()&quot;&gt;Submit&lt;/button&gt;

<!-- end snippet -->

答案2

得分: 0

我很抱歉,但我不太明白这个问题。

也许你正在寻找类似这样的东西。

<!-- begin snippet: js hide: true console: true babel: false -->

<!-- language: lang-js -->

$(document).ready(function(){
    $('#btn').attr('disabled',true);
    $('#rpw').keyup(function(){
        if($(this).val().length !=0)
          $('#btn').attr('disabled', false);            
        else
          $('#btn').attr('disabled',true);
    })
    $("#btn").click(function(){
      $("#pw").val() == $("#rpw").val() ?
      (window.alert('Successful!'), 
      $("#moveToNext").css("display", "block"))
      : (window.alert('Password not match!'),
      $("#moveToNext").css("display", "none"))
  });
});

<!-- language: lang-html -->

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

<label>Password: </label><input id="pw" type="password">
<br>
<label>Re-type Password: </label><input id="rpw" type="password">
<br>
<button id="btn">Check</button>
<div style="display:none;" id="moveToNext">
  <a href="mainmenu.html" onClick="checkPassword()">Move on the next stage</a>
</div>

<!-- end snippet -->
英文:

I'm sorry, but I don't quite understand the question.

Maybe you are looking for something like this.

<!-- begin snippet: js hide: true console: true babel: false -->

<!-- language: lang-js -->

$(document).ready(function(){
    $(&#39;#btn&#39;).attr(&#39;disabled&#39;,true);
    $(&#39;#rpw&#39;).keyup(function(){
        if($(this).val().length !=0)
          $(&#39;#btn&#39;).attr(&#39;disabled&#39;, false);            
        else
          $(&#39;#btn&#39;).attr(&#39;disabled&#39;,true);
    })
    $(&quot;#btn&quot;).click(function(){
      $(&quot;#pw&quot;).val() == $(&quot;#rpw&quot;).val() ?
      (window.alert(&#39;Successful!&#39;), 
      $(&quot;#moveToNext&quot;).css(&quot;display&quot;, &quot;block&quot;))
      : (window.alert(&#39;Password not match!&#39;),
      $(&quot;#moveToNext&quot;).css(&quot;display&quot;, &quot;none&quot;))
  });
});

<!-- language: lang-html -->

&lt;script src=&quot;https://code.jquery.com/jquery-3.6.0.min.js&quot;&gt;&lt;/script&gt;

&lt;label&gt;Password: &lt;/label&gt;&lt;input id=&quot;pw&quot; type=&quot;password&quot;&gt;
&lt;br&gt;
&lt;label&gt;Re-type Password: &lt;/label&gt;&lt;input id=&quot;rpw&quot; type=&quot;password&quot;&gt;
&lt;br&gt;
&lt;button id=&quot;btn&quot;&gt;Check&lt;/button&gt;
&lt;div style=&quot;display:none;&quot; id=&quot;moveToNext&quot;&gt;
  &lt;a href=&quot;mainmenu.html&quot; onClick=&quot;checkPassword()&quot;&gt;Move on the next stage&lt;/a&gt;
&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年5月10日 14:30:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/76215476.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定