【发布时间】:2021-06-12 03:37:03
【问题描述】:
我的标记文件中有多个<div class="collapsible-header"> 类,我想知道是否可以使用javascript 来获取带有该标记的所有元素并将字体系列设置为Roboto
这是文件的示例部分
<!DOCTYPE html>
<html lang="en" xmlns:width="http://www.w3.org/1999/xhtml">
<head>
<!--libraries and references-->
</head>
<body>
<div class="collapsible-header" >
<span class="material-icons" style="font-size: 50px">
developer_mode
</span>
<span style="text-align: right">Cross Platform</span>
</div>
<div class="collapsible-body"><span>With Java's Virtual Machine, any program written in Java can be ported to Windows, Solaris, Linux, macOS and
ran with success.</span></div>
<script>
<!--Code to get all tags with that class and set font to Roboto-->
</script>
【问题讨论】:
-
这当然是可能的。您遇到的问题是什么?
-
@CodeTiger,您要定位并应用“Font-Family”Roboto 的标签或类?
-
@Riyaz Khan,所有课程都带有
collapsible-header -
@Emiel Zuuriber,这些标签太多了,我无法保持样式,如果可能的话,我只想用 js 遍历所有标签
-
为什么不直接使用 CSS?循环遍历元素并更改它们的字体似乎不是一个好的解决方案。
标签: javascript html font-family