你可以试试它的纯 Javascript
<script>
function applyit()
{
var ref = document.querySelector("#divel");
var bdy = document.getElementsByTagName("body")[0];
var style = (bdy.querySelector("#thm") || document.createElement("style"));
style.setAttribute("id","thm");
var reqCSS = prompt("Enter the CSS Body","color:#AA5533;");
style.innerHTML = ".cus{"+reqCSS+"}";
bdy.appendChild(style);
ref.setAttribute("class","cus");
}
</script>
<style> .def { color:#0000FF; } </style>
<div id="divel" class="def">
<h3>This is a heading in a div element Which Has The Color Change</h3>
<p>This is p tag in a div element Which Has The Color Change.</p>
</div>
<p onclick="applyit();">Click Here To Change The Color For Heading and p tag.</p>
注意:我们可以将 User Preferred 样式存储在 browserStorage/Server 中以改善 UserExperience