[英](Javascript) How do you ignore lower/upper case being registered in search bars when searching for a specific item
I am tasked with constructing a search engine for a website that displays various pictures that all have different titles. 我的任务是为一个网站构建一个搜索引擎,该网站显示各种具有不同标题的图片。 Ie,
"Pictures of birds"
, "Flying birds"
, "Green Birds"
. 即,
"Pictures of birds"
, "Flying birds"
, "Green Birds"
。 As of now when I type in "birds"
only the first two results will display. 截至目前,当我输入
"birds"
只会显示前两个结果。
How can I ignore case sensitive searches, so that when a user types in "birds"
all three searches will come up. 如何忽略区分大小写的搜索,以便当用户键入
"birds"
所有三个搜索。
I hear converting the string to say all uppercase/lowercase could ignore it. 我听说将字符串转换为所有大写/小写字母都可以忽略它。 However, I am unfamiliar with exactly how I would implement this.
但是,我并不确切地知道如何实现这一点。
As of now I have this line of code within my function: 到目前为止,我的函数中包含以下代码行:
var str = document.getElementById('searchTxt').value;
var upper = str.toUpperCase();
console.log(str);
I am trying to print the value in the variable to the console
. 我试图将变量中的值打印到
console
。 Nothing is working and on the console only 2 objects are defined. 什么都没用,在控制台上仅定义了两个对象。
If someone could explain what I would need to do to get my code functioning, i'd be grateful. 如果有人可以解释我需要做些什么来使我的代码正常运行,我将不胜感激。
You are logging the unconverted string to the console. 您正在将未转换的字符串记录到控制台。
console.log(upper);
should do the trick 应该可以
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.