簡體   English   中英

如何以javascript格式更改占位符的顏色?

[英]How to change color of placeholder in javascript format?

如何將占位符的顏色更改為白色? 我知道我必須使用-moz-placeholder但我不知道如何將其格式化為JAVASCRIPT。 我需要以javascript的格式匹配下面的代碼。

           //User Name Input
            var inputUserName = document.createElement("input");
            inputUserName.type = "text";
            inputUserName.style.bottom = "220px";
            inputUserName.style.width = "170px";
            inputUserName.style.height = "20px";
            inputUserName.style.left = "50px";
            inputUserName.style.textAlign = "center";
            inputUserName.style.display = "none";
            inputUserName.style.backgroundColor = "transparent";
            inputUserName.style.borderBottom = "2px solid black";
            inputUserName.style.borderTop = "transparent";
            inputUserName.style.borderLeft = "transparent";
            inputUserName.style.borderRight = "transparent";
            inputUserName.placeholder = "User Name";
            inputUserName.style.color = "white";
            inputUserName.style.position = "absolute";
            inputUserName.className = "UserNameSignUp";
            inputUserName.UserNameSignUp = "-moz-placeholder";
        //input.className = "css-class-name"; // set the CSS class
        formArea.appendChild(inputUserName); // put it into the DOM

-moz-placeholder是一個偽類,因此不直接作為DOM的一部分,因此您無法以相同的方式編輯它或為其添加內聯樣式。

解決方法是動態更改樣式表

document.styleSheets[0].insertRule('#xyz:-moz-placeholder { background-color: white; }', 0);

考慮到它有一些id(“#xyz”)。

請參閱此文檔以供參考: https//developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/insertRule

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM