Placeholder.js在文本框控件ASP.NET中将水印添加为文本

时间:2016-06-21 05:55:57

标签: c# asp.net internet-explorer

enter image description here

在IE-9中如果文本框留黑并允许搜索水水

“请求类型”

追加查询作为搜索条件,任何忽略水印文本的placeholder.js修复

在Chrome中完美运作

1 个答案:

答案 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]-->