2015-06-29 19 views
0

我有一个简单的表单。加载页面时,输入字段为空,只有在单击字段时才显示占位符。占位符仅在点击HTML后出现JS

<input type="text" onblur="if(this.value=='') this.value='Vorname, 
Name';"  onfocus="if(this.value=='Vorname, Name')  
this.value='';"   name="dynamic_0" title="Vorname, Name" value=""> 

我怎样才能让页面加载时显示占位符?

+1

使用属性占位符设置的占位符。 – RobertoNovelo

回答

1

使用HTML占位符元素

<input type="text" placeholder="whatever you want" onblur="if(this.value=='') this.value='Vorname, Name';"  onfocus="if(this.value=='Vorname, Name') this.value='';"   name="dynamic_0" title="Vorname, Name" value="">

旧IE的兼容性,你应该看看这个填充工具藏汉: https://github.com/ginader/HTML5-placeholder-polyfill