1
<div>
<b> some test
</div>
another text

This would print the "another text" bold. Is it some how possible to limit the effect of <b> only within the <div> element? I've searched the web for some javascript solutions but couldn't find anything.

Please don't ask why I need this. Just lets assume it's out of curiosity.

Thanks

4

2 回答 2

0

关闭粗体标签,如下所示。这是基本的 HTML。

<div>
    <b>some text</b>
</div>
Another text

更多关于 html 的信息:http: //www.w3schools.com/html/

于 2012-07-12T03:44:46.343 回答
0

一个有趣但可行的解决方案是在元素的 innerHTML 中注入结束标记。

让我们想想:

jQuery

$('div').each(function(){
   $(this).append("</b></i></u></s></small></code>");
});

纯 JavaScript

var dv=document.getElementsByTagName('div');
for (var i=0;i<dv.length;i++) {
    dv[i].innerHTML += "</b></i></u></s></small></code>";
}

这是一个非常糟糕的做法,因为您应该始终注意关闭您可能打开的每个标签,但是如果它们尚未关闭,这将关闭格式化标签。

于 2012-07-12T03:57:45.857 回答