看看这个代码......
HTML
<span>TEST </span>
<div style="color:red">COlured div</div>
<div style="color:blue">COlured div</div>
<p style="color:red">Colourful TExt</p>
<p style="color:blue">Colourful TExt</p>
<p style="color:green">Colourful TExt</p>
<p style="color:brown">Colourful TExt</p>
<button onclick="changetobw()">CHANGE COLOR</button>
Run Code Online (Sandbox Code Playgroud)
JavaScript的
function changetobw() {
a = document.getElementsByTagName('p');
b = document.getElementsByTagName('div');
var i = 0;
do {
a[i].classList.add('nocolor');
b[i].classList.add('nocolor');
i++;
} while (i < a.length && i < b.length);
}
Run Code Online (Sandbox Code Playgroud)
CSS
.nocolor {
color:#000 !important;
}
Run Code Online (Sandbox Code Playgroud)
我在这里尝试做的是点击按钮使所有div和span字体颜色"黑色".
当计数器越过i = 2时,我的代码(显然)断开,因为只有2个div,因此"i [2]"将是未定义的,因此循环中断.
无论如何,在击中这一点后,循环不会破坏?也许我没有完全理解我的观点.希望大家都明白吗?
如何使用javascript在数组列表中用'/'替换','.这里我的数组列表有两个字符串'值用逗号分隔','但是我希望以单个字符串的形式将它用'/'分隔?
例如:array [] = { value1, a1/a2/a3}由array [] =替换{value1/a1/a2/a3}
例如:在这里,我要替换这是作为结果[3,101/102/103]的[3/101/102/103].
任何人都可以建议吗?
我有一个问题,我需要在H2标签内插入一个div.
那可能吗.我认为应该.只想到我不知道如何完成它.我尝试了以下内容
HTML
<h2 id="strap">Blah Blah & Some More Blah Blah Blah
<div class="section contain">
<a href="http://www.facebook.com/BlahBlah" rel="nofollow" target="_blank"><img alt="facebook" src="<%=SkinPath %>img/social/fb.png"/></a>
<a href="http://twitter.com/BlahBlah" rel="nofollow" target="_blank"><img alt="twitter" src="<%=SkinPath %>img/social/tw.png"/></a>
<a href="http://BlahBlah.wordpress.com/" rel="nofollow" target="_blank"><img alt="blog" src="<%=SkinPath %>img/social/wp.png"/></a>
</div>
</h2>
Run Code Online (Sandbox Code Playgroud)
我希望div元素(社交图标)出现在同一行.有没有其他方法这样做?
我有一个简单的c ++程序,它具有返回字符串的功能.
#include <iostream>
#include <string>
using namespace std;
int main(){
/// Some Code;
string text= converter (i);
/// Some more code
}
string converter(int number)
{
switch (number) {
case 1:
return "one";
break;
case 2:
return "two";
break;
default:
cout << "Invalid";
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试编译这个时,我得到以下错误..
error C3861: 'converter': identifier not found
Run Code Online (Sandbox Code Playgroud)
可能是什么问题呢?