你可以試試這個它的純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>
注: 我們可以存儲用戶瀏覽器存儲/服務器中的首選樣式,以提高用戶體驗
如果我在此腳本中進行更改,它將起作用 – Nokia808Freak
是的,它會工作 –
OK謝謝您的回覆 – Nokia808Freak