我有一个带有文本区和标签的HTML页面,我需要在文本区中写CSS类,并使用标签:
<textarea id="txtCSS" name="txtCSS" rows="4" cols="50">
.FC{color:green;}
</textarea>
<label class="FC">Some Text</label>
怎么做。
试试这个
null
const css = function() {
const [_,clas,css] = document.getElementById("txtCSS").value.match(/\.(\w+){(.*)}/)
document.querySelector("."+clas).style=css;
}
document.getElementById("txtCSS").addEventListener("input",css)
css()
<textarea id="txtCSS" name="txtCSS" rows="4" cols="50">
.FC{color:green;}
</textarea>
<label class="FC">Some Text</label>