寻求实现 HTML5  Placeholder的优雅解决方案
input.onfocus = function(){
    if(this.value == this.getAttribute("placeholder") this.value = "";
}input.onblur = function(){
    if(this.value == "") this.value j= this.getAttribute("placeholder");
}很明显这是有bug的。假设有如下<input placeholder="blackberry" />当用户正巧输入 "blackberry" 的时候,,那么焦点丢失时。。悲剧发生了..寻求解决方案 TKS

解决方案 »

  1.   

    http://cssrainbow.cn/demos/892.html
    楼主可以看看这里。
      

  2.   

    if(!("placeholder" in document.createElement("input"))){
    input.value = input.getAttribute("placeholder");
    input.style.color = "#999";
    input.onfocus = function(){
    if(this.style.color == "#999"){
    this.value = "";
    this.style.color = "";
    }
    }
    input.onblur = function(){
    if(this.value == ""){
    this.value = this.getAttribute("placeholder");
    this.style.color = "#999";
    }
    }
    }