通过JS修改html标签属性
<pre><codeclass="language-bash">xxxx</code></pre>通过js实现,当<code>标签的类有"language-bash"时(...
<pre>
<code class="language-bash">
xxxx
</code>
</pre>
通过js实现,当<code>标签的类有"language-bash"时(如上所示)
父标签<pre>的属性变为<pre class="command-line language-bash" data-user="root" data-host="localhost">
(如下所示)
<pre class="command-line language-bash" data-user="root" data-host="localhost">
<code class="language-bash">
xxxx
</code>
</pre> 展开
<code class="language-bash">
xxxx
</code>
</pre>
通过js实现,当<code>标签的类有"language-bash"时(如上所示)
父标签<pre>的属性变为<pre class="command-line language-bash" data-user="root" data-host="localhost">
(如下所示)
<pre class="command-line language-bash" data-user="root" data-host="localhost">
<code class="language-bash">
xxxx
</code>
</pre> 展开
展开全部
<pre>
<code class="language-bash">
xxxx
</code>
</pre>
<script>
window.onload=function(){
var codes=document.getElementsByTagName("code");
for(var i in codes){
if(codes[i].className&&codes[i].className.indexOf("language-bash")>-1){
codes[i].parentNode.className="command-line language-bash";
codes[i].parentNode.dataset.user="root";
codes[i].parentNode.dataset.host="localhost";
}
}
}
</script>
追问
书生大哥,我记得你,上次也是你帮的我,谢啦2333
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询