如果不能写到CSS里面,可不可以写到js里面?
属性从来不能写到 CSS 里边。
JavaScript 能够构建整个页面,当然能给一些元素加上指定的标签,比如:
Array.prototype.slice.call(document.getElementsByTagName('a')).forEach(function(a){
a.setAttribute('target', '_blank');
});
额,我刚试了一下,可以啊。。。。
<style type="text/css">
a[target="_blank"] {
color:red;
}
</style>
<a href="http://.com" target="_blank">SegmentFault</a>