- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
长话短说,我正在尝试为一个项目进行密码强度测试,但我想如果我不能在点击时接受输入然后将其放入我的函数中,我将无法到达任何地方测试并发回。
但基本上第一步我就被难住了。
我现在的目标是让火车开动,能够点击按钮,然后将中间的大强度文本更改为“它起作用了”或类似的东西,找到一种方法来调用该函数并正确使用它。
(仅供引用,我正在制作一个密码生成器,就像二合一交易一样,这就是为什么有一个额外的按钮并且 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 属性。或者,如果它是一个表单控件,如输入或选择,那么您将设置 .value。由于您已将元素的 ID 设置为强度,因此您可以使用它来引用该元素。和 strength.innerHTML = “它成功了!”然后将更改屏幕上显示的内容。
运行代码片段以查看其工作原理。
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 - 如何调用函数 onclick,同时还更改函数外部文本的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72567517/
C语言sscanf()函数:从字符串中读取指定格式的数据 头文件: ?
最近,我有一个关于工作预评估的问题,即使查询了每个功能的工作原理,我也不知道如何解决。这是一个伪代码。 下面是一个名为foo()的函数,该函数将被传递一个值并返回一个值。如果将以下值传递给foo函数,
CStr 函数 返回表达式,该表达式已被转换为 String 子类型的 Variant。 CStr(expression) expression 参数是任意有效的表达式。 说明 通常,可以
CSng 函数 返回表达式,该表达式已被转换为 Single 子类型的 Variant。 CSng(expression) expression 参数是任意有效的表达式。 说明 通常,可
CreateObject 函数 创建并返回对 Automation 对象的引用。 CreateObject(servername.typename [, location]) 参数 serv
Cos 函数 返回某个角的余弦值。 Cos(number) number 参数可以是任何将某个角表示为弧度的有效数值表达式。 说明 Cos 函数取某个角并返回直角三角形两边的比值。此比值是
CLng 函数 返回表达式,此表达式已被转换为 Long 子类型的 Variant。 CLng(expression) expression 参数是任意有效的表达式。 说明 通常,您可以使
CInt 函数 返回表达式,此表达式已被转换为 Integer 子类型的 Variant。 CInt(expression) expression 参数是任意有效的表达式。 说明 通常,可
Chr 函数 返回与指定的 ANSI 字符代码相对应的字符。 Chr(charcode) charcode 参数是可以标识字符的数字。 说明 从 0 到 31 的数字表示标准的不可打印的
CDbl 函数 返回表达式,此表达式已被转换为 Double 子类型的 Variant。 CDbl(expression) expression 参数是任意有效的表达式。 说明 通常,您可
CDate 函数 返回表达式,此表达式已被转换为 Date 子类型的 Variant。 CDate(date) date 参数是任意有效的日期表达式。 说明 IsDate 函数用于判断 d
CCur 函数 返回表达式,此表达式已被转换为 Currency 子类型的 Variant。 CCur(expression) expression 参数是任意有效的表达式。 说明 通常,
CByte 函数 返回表达式,此表达式已被转换为 Byte 子类型的 Variant。 CByte(expression) expression 参数是任意有效的表达式。 说明 通常,可以
CBool 函数 返回表达式,此表达式已转换为 Boolean 子类型的 Variant。 CBool(expression) expression 是任意有效的表达式。 说明 如果 ex
Atn 函数 返回数值的反正切值。 Atn(number) number 参数可以是任意有效的数值表达式。 说明 Atn 函数计算直角三角形两个边的比值 (number) 并返回对应角的弧
Asc 函数 返回与字符串的第一个字母对应的 ANSI 字符代码。 Asc(string) string 参数是任意有效的字符串表达式。如果 string 参数未包含字符,则将发生运行时错误。
Array 函数 返回包含数组的 Variant。 Array(arglist) arglist 参数是赋给包含在 Variant 中的数组元素的值的列表(用逗号分隔)。如果没有指定此参数,则
Abs 函数 返回数字的绝对值。 Abs(number) number 参数可以是任意有效的数值表达式。如果 number 包含 Null,则返回 Null;如果是未初始化变量,则返回 0。
FormatPercent 函数 返回表达式,此表达式已被格式化为尾随有 % 符号的百分比(乘以 100 )。 FormatPercent(expression[,NumDigitsAfterD
FormatNumber 函数 返回表达式,此表达式已被格式化为数值。 FormatNumber( expression [,NumDigitsAfterDecimal [,Inc
我是一名优秀的程序员,十分优秀!