0

1)我会在某些条件下使用javascript更改输入占位符颜色(如果它会永远更改占位符颜色,则不是CSS)2)我希望占位符在输入框上更改为另一个占位符。我得到了这个功能:

if(email.value==''){
email.style.borderColor = "#FF0000";
email.setAttribute('placeholder',"Plea… fill this required field");
//code for changing the placeholder color
//code for changing the placeholder onmouseover
}

1)占位符颜色对我来说通常是“#C9C9C9”我想通过这个代码把它改成另一种颜色。2)我希望占位符文本在鼠标悬停时更改为任何其他文本。我会感谢给我代码的人。

谢谢

4

1 回答 1

4

Look with this post's answer to do it in CSS : Change an HTML5 input's placeholder color with CSS

Then, you can include the CSS rule with javascript.

And you just have to use pseudo-class :hover for the mouseover.

Just like that :

CSS

input.formInvalid::-webkit-input-placeholder {
   color: red;
}

Javascript

document.getElementById("yourElementId").className += " formInvalid"; //add the class .formInvalid to your element
于 2012-11-30T10:51:18.150 回答