在javascript中处理提示?

时间:2016-01-08 23:57:55

标签: javascript css html5 cue

我想从我的css中删除它:

::cue  {
    color: #fff;
    font-family: "Trebuchet MS",Helvetica,sans-serif;
    text-shadow: -1px 0 black,0 1px black,1px 0 black,0 -1px #000;
}

并将其放入我的javascript中。我该怎么做?

2 个答案:

答案 0 :(得分:0)

嗨,这是一个你可以使用的例子。

html page

<html>
    <head>
        <title></title>
        <link rel="stylesheet" type="text/css" href="styles/styles.css" defer/>
        <script src="JS/script.js"></script>
    </head> 
<body> 
   <h1 id="cue">Hello World</h1>
   <button id="btnText">Change Text</button>    

</body
</html>

javascript file

window.onload = function () {

    "use strict";

    var myText = document.getElementById("cue"),
        btnChange = document.getElementById("btnText");

    btnChange.addEventListener("click", function () {

        myText.style.color = "white";
        myText.style.fontFamily = "Trebuchet MS, Helvetica,sans-serif";
        myText.style.textShadow = "-1px 0 black, 0 1px black, 1px 0 black, 0 -1px #000";    
    })
};

答案 1 :(得分:0)

感谢Dandavis,这是一个有效的解决方案:

&#13;
&#13;
var s = document.createElement("style");
    s.type = "text/css";
    s.innerHTML = "::cue  {"
        + "background:none;"
        + "color: #fff;"
        + "font-family: 'Trebuchet MS',Helvetica,sans-serif;"
        + "text-shadow: -1px 0 black,0 1px black,1px 0 black,0 -1px #000;"
        + "}";

document.head.appendChild(s);
&#13;
&#13;
&#13;