2017-04-12 4 views
0

어떻게 자리 표시 자의 색을 흰색으로 변경합니까? -moz-placeholder를 사용해야한다는 것을 알고 있지만 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의 일부가 아닌, 그래서 당신은 그것을 같은 방식으로 편집하거나 인라인 스타일을 추가 할 수 없습니다.

해결 방법은 신분증 ("#의 XYZ")를 가지고 고려 동적

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

같은 스타일을 변경하는 것입니다.

참조 용으로이 설명서를 참조하십시오. https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/insertRule