我想在調用mobileValidate()後更改此佔位符的顏色。如何使用javascript更改佔位符的顏色?
<input type="text" class="form-control" name="InputMobile" id="Mobile" placeholder="Enter Mobile Number" onblur="mobileValidate()"required>
JavaScript函數是
function mobileValidate(){
var x = document.getElementById("Mobile");
if ((x.value).match(re)){
alert("mobile Number is valid");
}
else{
alert("mobile no is not valid");
x.value="";
x.placeholder.style.color="red";
}
}
此鏈接可能會幫助你:http://stackoverflow.com/questions/2610497/change-an-inputs-html5-placeholder-color-with-css –