2017-04-12 57 views
0

如何將佔位符的顏色更改爲白色?我知道我必須使用-moz佔位符,但我不知道如何將其格式化爲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的一部分,所以你不能編輯它以同樣的方式或添加內嵌樣式它。

一種解決方法是改變樣式表動態像

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

考慮到它有一定的ID( 「#XYZ」)。

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

相關問題