答案 0 :(得分:0)
IE-9不确定占位符。据我所知 - 这是你的问题。因此,如果你需要在IE-9中使用它,你可以得到这样的东西:
HTML
<input type="text" value="" placeholder="E-mail-1">
<input type="text" value="" placeholder="E-mail-2">
<input type="text" value="Value" placeholder="E-mail-3">
CSS:
<style type="text/css">
.placeholdr { color: gray }
</style>
没有JQuery的JS代码:
<!--[if IE 9]>
<script type="text/javascript">
(function setPlaceHolders(){
var input = document.getElementsByTagName('input'); // get all text fields
var cls = "placeholdr"; // set name of the class
if (input) { // if fields found
for (var i=0; i < input.length; i++) {
var t = input[i];
var txt = t.getAttribute("placeholder");
if (txt.length > 0) { // if placeholder found
t.className = t.value.length == 0 ? t.className+" "+cls : t.className; // add class
t.value = t.value.length > 0 ? t.value : txt; // if no value found
t.onfocus = function() { // on focus
this.className = this.className.replace(cls);
this.value = this.value == this.getAttribute("placeholder") ? "" : this.value;
}
t.onblur = function() { // on focus out
if (this.value.length == 0) {
this.value = this.getAttribute("placeholder");
this.className = this.className+" "+cls; // add class
}
}
}
}
}
})();
</script>
<![endif]-->