2017-04-12 17 views
0

プレースホルダの色を白に変更するにはどうすればよいですか?私は-moz-placeholderを使う必要があることを知っていますが、JAVASCRIPTにフォーマットする方法はわかりません。私は私が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 

答えて

0

-moz-プレースホルダ疑似クラスであるため、直接DOMの一部ではありませんので、あなたはそれを同じ方法で編集したり、それにインラインスタイルを追加することはできません。

この問題を回避するには、それはいくつかのID( "#のXYZ")を有する考慮

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

のように動的にスタイルシートを変更することになります。

参照のためにこのドキュメントを参照してください: https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/insertRule

関連する問題