如何将数组中的字符串设置为显示:无?JavaScript
完整HTML:如何将数组中的字符串设置为显示:无?JavaScript,javascript,arrays,string,Javascript,Arrays,String,完整HTML: <!DOCTYPE html> <html> <head> <title>Seth J. Freeman - WTMP</title> <link rel="stylesheet" href="/HomePage/home.css"> </head> <body> <script src="/Resource
<!DOCTYPE html>
<html>
<head>
<title>Seth J. Freeman - WTMP</title>
<link rel="stylesheet" href="/HomePage/home.css">
</head>
<body>
<script src="/Resources/jquery-3.1.1.js"></script>
<script src="/Resources/JQueryPlugins/Ease.js"></script>
<script type="text/javascript">
function codeAddress() {
// Gathers string content
var el = document.querySelectorAll(".con-1");
// Stores text, and prepares it for use
var myString = el[0].textContent;
// Sets a blank array ready to store myString characters at certain positions
var matchedIndexes = [];
// Main function, Gathers characters W,T,M,P in myString
// As long as (I) has a lower value than myStrings length it keeps searching for characters
for (var i = 0; i < myString.length; i++) {
// Gathers characters W T M P
if (myString[i] == "W" || myString[i] == "T" || myString[i] == "M" || myString[i] == "P") {
matchedIndexes.push(new myMatch(myString[i], i));
}
}
// Prints to console matchedIndexes array
console.log(matchedIndexes);
function myMatch(position, character) {
// Writes to console the position of the character
this.position = position;
// Writes to console the character that was collected
this.character = character;
}
}
// When the window is loaded call codeAddress function
window.onload = codeAddress;
</script>
<div class="pro-1">
<div class="con-1 noselect">Welcome To My Playground</div>
<div class="sod-1 noselect">Stuff Happens Here.</div>
</div>
</body>
// Main function, Gathers characters W,T,M,P in myString
// As long as (I) has a lower value than myStrings length it keeps searching for characters
for (var i = 0; i < myString.length; i++) {
// Gathers characters W T M P
if (myString[i] == "W" || myString[i] == "T" || myString[i] == "M" || myString[i] == "P") {
matchedIndexes.push(new myMatch(myString[i], i));
}
}
赛斯·J·弗里曼-WTMP
函数代码地址(){
//收集字符串内容
var el=document.queryselectoral(“.con-1”);
//存储文本,并准备使用
var myString=el[0].textContent;
//设置一个空白数组,准备在某些位置存储myString字符
var MatchedIndex=[];
//Main函数,在myString中收集字符W、T、M、P
//只要(I)的值小于myStrings length,它就会继续搜索字符
for(var i=0;i
指向特定问题:
<!DOCTYPE html>
<html>
<head>
<title>Seth J. Freeman - WTMP</title>
<link rel="stylesheet" href="/HomePage/home.css">
</head>
<body>
<script src="/Resources/jquery-3.1.1.js"></script>
<script src="/Resources/JQueryPlugins/Ease.js"></script>
<script type="text/javascript">
function codeAddress() {
// Gathers string content
var el = document.querySelectorAll(".con-1");
// Stores text, and prepares it for use
var myString = el[0].textContent;
// Sets a blank array ready to store myString characters at certain positions
var matchedIndexes = [];
// Main function, Gathers characters W,T,M,P in myString
// As long as (I) has a lower value than myStrings length it keeps searching for characters
for (var i = 0; i < myString.length; i++) {
// Gathers characters W T M P
if (myString[i] == "W" || myString[i] == "T" || myString[i] == "M" || myString[i] == "P") {
matchedIndexes.push(new myMatch(myString[i], i));
}
}
// Prints to console matchedIndexes array
console.log(matchedIndexes);
function myMatch(position, character) {
// Writes to console the position of the character
this.position = position;
// Writes to console the character that was collected
this.character = character;
}
}
// When the window is loaded call codeAddress function
window.onload = codeAddress;
</script>
<div class="pro-1">
<div class="con-1 noselect">Welcome To My Playground</div>
<div class="sod-1 noselect">Stuff Happens Here.</div>
</div>
</body>
// Main function, Gathers characters W,T,M,P in myString
// As long as (I) has a lower value than myStrings length it keeps searching for characters
for (var i = 0; i < myString.length; i++) {
// Gathers characters W T M P
if (myString[i] == "W" || myString[i] == "T" || myString[i] == "M" || myString[i] == "P") {
matchedIndexes.push(new myMatch(myString[i], i));
}
}
//主函数,在myString中收集字符W、T、M、P
//只要(I)的值小于myStrings length,它就会继续搜索字符
for(var i=0;i
说明:
<!DOCTYPE html>
<html>
<head>
<title>Seth J. Freeman - WTMP</title>
<link rel="stylesheet" href="/HomePage/home.css">
</head>
<body>
<script src="/Resources/jquery-3.1.1.js"></script>
<script src="/Resources/JQueryPlugins/Ease.js"></script>
<script type="text/javascript">
function codeAddress() {
// Gathers string content
var el = document.querySelectorAll(".con-1");
// Stores text, and prepares it for use
var myString = el[0].textContent;
// Sets a blank array ready to store myString characters at certain positions
var matchedIndexes = [];
// Main function, Gathers characters W,T,M,P in myString
// As long as (I) has a lower value than myStrings length it keeps searching for characters
for (var i = 0; i < myString.length; i++) {
// Gathers characters W T M P
if (myString[i] == "W" || myString[i] == "T" || myString[i] == "M" || myString[i] == "P") {
matchedIndexes.push(new myMatch(myString[i], i));
}
}
// Prints to console matchedIndexes array
console.log(matchedIndexes);
function myMatch(position, character) {
// Writes to console the position of the character
this.position = position;
// Writes to console the character that was collected
this.character = character;
}
}
// When the window is loaded call codeAddress function
window.onload = codeAddress;
</script>
<div class="pro-1">
<div class="con-1 noselect">Welcome To My Playground</div>
<div class="sod-1 noselect">Stuff Happens Here.</div>
</div>
</body>
// Main function, Gathers characters W,T,M,P in myString
// As long as (I) has a lower value than myStrings length it keeps searching for characters
for (var i = 0; i < myString.length; i++) {
// Gathers characters W T M P
if (myString[i] == "W" || myString[i] == "T" || myString[i] == "M" || myString[i] == "P") {
matchedIndexes.push(new myMatch(myString[i], i));
}
}
我要做的是收集字母W、T、M、p,并将它们从整个字符串中分离出来。当它们分开时,我只想更改这些字母的显示属性。到目前为止,我已经得到了JS代码来收集字符W、T、M、P和打印到控制台的位置以及收集的字符。有什么方法可以更改数组myString中这些字符的显示属性吗?1st call函数您应该这样做
window.onload=codeAddress()
而不是window.onload=code地址代码>
第二,我删除了myMatch
功能,除非您需要保存索引
第三,我使用updatedHtml
保存更新后的html,因为你可以看到一个字母是否匹配,只需保存它,否则用
包装它。此hid
类具有css可见性:隐藏代码>将隐藏内容,但仍占用空间。如果希望空间也消失,可以将其更改为display:none
函数代码地址(){
//收集字符串内容
变量el=$(“.con-1”);
//存储文本,并准备使用
var myString=el[0].textContent;
//保存更新的html
var updatedHtml=[];
//Main函数,在myString中收集字符W、T、M、P
//只要(I)的值小于myStrings length,它就会继续搜索字符
for(var i=0;i
.hid{
可见性:隐藏;
}
欢迎来到我的操场
这里发生了很多事情。
第一次调用函数您应该执行此操作window.onload=codeAddress()
而不是window.onload=code地址代码>
第二,我删除了myMatch
功能,除非您需要保存索引
第三,我使用updatedHtml
保存更新后的html,因为你可以看到一个字母是否匹配,只需保存它,否则用
包装它。此hid
类具有css可见性:隐藏代码>将隐藏内容,但仍占用空间。如果希望空间也消失,可以将其更改为display:none
函数代码地址(){
//收集字符串内容
变量el=$(“.con-1”);
//存储文本,并准备使用
var myString=el[0].textContent;
//保存更新的html
var updatedHtml=[];
//Main函数,在myString中收集字符W、T、M、P
//只要(I)的值小于myStrings length,它就会继续搜索字符
for(var i=0;i
.hid{
可见性:隐藏;
}
欢迎来到我的操场
这里发生了很多事情。
要找到这些字母并突出显示,隐藏其他所有内容吗?是的。这正是我想做的。嗨@Seth J.Freeman我也更新了更多信息和代码,希望能有所帮助=你想找到那些字母并突出显示,隐藏其他所有内容吗?是的。这正是我想要做的。嗨@Seth J.Freeman我也更新了更多的信息和代码,希望对你有所帮助