这里的程序员比较新,不要太难判断

长话短说,我正在try 为一个项目进行密码强度测试,但我想如果我不能在单击时获取输入,然后将其放入我的函数中,然后测试并发送回来,我将无法获得任何结果.

但我基本上在第一步就被难住了.

我现在的目标是让火车开动,就是能够单击按钮,然后将中间的大强度文本更改为"it worked"或类似的内容,以找到调用函数并正确使用它的方法.

(仅供参考,我也在为二合一交易制作一个密码生成器,这就是为什么有一个额外的按钮,css文件有一些"冗余"代码的原因)

非常感谢您的帮助<3.

/* Background color + text colour and centering */
body {
    background-color: black;
    color: black;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0%;
    font-family: Arial, Helvetica, sans-serif;
}
/* div block */
.container {
    background-color: yellow;
    padding: 3rem;
    border: 2px solid white;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
}
/* spacing out text and inputs */
.form {
    display: grid;
    grid-template-columns: auto auto;
    row-gap: 1rem;
    column-gap: 3rem;
    justify-content: center;
    align-items: center;
}

.title {
    text-align: center;

}

/* Making text easier to see/read */
label {
    font-weight: bold;
}
.characteramountrange {
    display: flex;
}

.number-input {
    width: 2rem;
}

/*display box*/
.password-display {
    background-color: white;
    color: black;
    padding: 1rem;
    border: 1px solid black;
    height: 2rem;
    width: 350px;
    display: flex;
    justify-content: center;
    align-items: center;
    word-break: break-all;
}
/* Customizing the style of the "Generate" Button */
.button {
    grid-column: span 2;
    background-color: white;
    border: 2px solid black;
    color: black;
    padding: .5rem 1rem;
    font-weight: bold;
    cursor: pointer;
}

.button:hover {
    background-color: #FFFFFF33;
}
/* redirect button */
.btn {
    background-color: white;
    border: 2px solid black;
    color: black;
    font-weight: bold;
    cursor: pointer;
    padding: 5px;
}
.btn:hover {
    background-color: #FFFFFF33;
}
   
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <link rel="stylesheet" href="styles.css">
  <title>Password Strength Test</title>
</head>
<body>
  <div class="container">
    <h1 class="title">Password Strength Test</h1>
    <input type="text" class= "password" value= "password" id="password">
    <form id="passwordGeneratorForm" class="form">
      <h1 id="strength">Strength</h1>
      <button type="button" class="button" onclick="PasswordTest()" id="btn">Check Strength</button>
      <a href="index.html" class="btn" style="text-decoration: none;">Password Generator</a>
    </form>
    <script>
      function PasswordTest() {
        document.getElementById("strength")
        let strength = "it worked"
        return strength;
      }
    </script>
    </section>
  </div>
</body>
</html>

推荐答案

要使代码正常工作,请更改此行:

let strength = "it worked"

收件人:

strength.innerHTML = "it worked"

要更改html元素的内容,需要设置.innerHTML或.innerText属性.或者,如果它是一个表单控件,如输入或 Select ,则可以设置.价值由于已将元素的ID设置为strength,因此可以使用该ID引用元素.和力量.innerHTML="成功了!"然后将更改屏幕上显示的内容.

Run the snippet to see how it works.

function PasswordTest() {
  strength.innerHTML = "it worked"
}
<input type="text" class="password" placeholder="password" id="password">
<h1 id="strength">Strength</h1>
<button type="button" class="button" onclick="PasswordTest()" id="btn">Check Strength</button>

Javascript相关问答推荐

如何最好地从TypScript中的enum获取值

Chromium会将URL与JS一起传递到V8吗?

虚拟滚动实现使向下滚动可滚动到末尾

使用Nuxt Apollo在Piniastore 中获取产品细节

如何将zoom 变换应用到我的d3力有向图?

Reaction Redux&Quot;在派单错误中检测到状态Mutations

有效路径同时显示有效路径组件和不存在的路径组件

如何找到带有特定文本和测试ID的div?

是否可以在不更改组件标识的情况下换出Reaction组件定义(以维护状态/引用等)?如果是这样的话,是如何做到的呢?

JavaScript&;Reaction-如何避免在不使用字典/对象的情况下出现地狱?

为什么NULL不能在构造函数的.Prototype中工作

我无法在Api Reaction本机上发出GET请求

Angel Auth Guard-用户只有在未登录时才能访问登录页面,只有在登录时才能访问其他页面

如何在移动设备中使用JAVASSCRIPT移除点击时的焦点/悬停状态

表单数据中未定义的数组键

计算对象数组中属性的滚动增量

每隔一行文本段落进行镜像(Boustrophedon)

递归地将JSON对象的内容上移一级

单击子按钮时将活动切换类添加到父分区

TS node 找不到依赖的模块