我的点击不在我使用false搜索时不断返回一个false
我正在使用该数组包含方法来对我的数组中的项目进行故意搜索,但是即使我在那里,它也会在单击按钮时返回false。
var arr = ["steve", "salewa", "Morris"]
var input = document.getElementById("mysearch")
var button = document.getElementById("but1")
but1.addEventListener("click", clicked)
function clicked() {
var output = arr.includes("input.value")
console.log(output)
}
<h1>search</h1>
<input type="search" id="mysearch" name="q" placeholder="...search">
<button id="but1">check</button>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用 noreflow noreferrer“> 滤除与指定条件匹配的数组值。您需要在数组的每个元素(=每个名称)上使用
incode()
,而不是在数组本身上,因为inclath inder()
在数组上仅返回true
或false
插入全名时。include()
在数组上工作及其在字符串上的工作方式有很小的区别。您想在名称包含输入字段中输入的内容的情况下返回结果。另外,您需要使用
input.value
从输入中获取值。如果您用“
”字符串“ Input.Value”
将使用,而不是您输入的内容。You should be using
filter()
to filter out the array values that match a specified condition. You want to useincludes()
on each element of the array (= each name), not on the array itself, becauseincludes()
on an array only returnstrue
orfalse
when the whole name is inserted. There is a slight difference howincludes()
works on an array and how it works on a string. You want to return results where the name contains what you entered in the input field.Also you need to get the value from the input using
input.value
. If you surround that with"
the string"input.value"
will be used, not what you entered.