使所有标题touppercase(); [英] Make all headings touppercase();
本文介绍了使所有标题touppercase();的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
将所有标题设为toUcapCase();没有使用id:s。
我尝试过:
Make all headings toUpperCase(); without using id:s.
What I have tried:
<!DOCTYPE html>
<p>Convert string to upper case:</p>
Try it
<h1> Hello World!</h1>
<h2> Hello World!</h2>
<h2> Hello World!</h2>
<h2> Hello World!</h2>
function myFunction() {
var text = document.querySelectorAll("h1, h2").innerHTML;
document.querySelectorAll("h1, h2") = text.toUpperCase();
}
推荐答案
有几种方法可以做到这一点。
1.通过JavaScript。请注意,querySelectorAll返回元素列表,因此需要循环来迭代其中的所有元素。
There are couple way to do it.
1. Through JavaScript. Note that querySelectorAll return list of elements, therefore a loop is required to iterate all the elements in it.
function myFunction() {
document.querySelectorAll('h1, h2').forEach(function(tag) {
tag.innerHTML = tag.innerHTML.toUpperCase();
});
}
myFunction() ;
2. CSS
2. CSS
h1, h2 {
text-transform: uppercase;
}
CP_upper case - JSFiddle [< a href =https://jsfiddle.net/bryiantan/29rxjs0k/target =_ blanktitle =New Window> ^ ]
这篇关于使所有标题touppercase();的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文