How to make a plug-in that supports the placeholder attribute of HTML5 under IE

  • 的头像-Tumi
  • 16 day agopublish

Zhe Pian Wen Zhang Jiang Wei Da Jia Xiang Xi Jiang Jie You Guan Ru He Rang IE Xia Zhi Chi Html5 De placeholder Shu Xing De Cha Jian , Xiao Bian Jue De Ting Shi Yong De , Yin Ci Fen Xiang Gei Da Jia Zuo Ge Can Kao , Xi Wang Da Jia Yue Du Wan Zhe Pian Wen Zhang Hou Ke Yi You Suo Shou Huo 。

HTML5 Dui Web Form Zuo Liao Xu Duo Zeng Qiang , Bi Ru input Xin Zeng De type Lei Xing 、Form Validation Deng 。

Placeholder Shi HTML5 Xin Zeng De Ling Yi Ge Shu Xing , Dang input Huo Zhe textarea She Zhi Liao Gai Shu Xing Hou , Gai Zhi De Nei Rong Jiang Zuo Wei Hui Zi Ti Shi Xian Shi Zai Wen Ben Kuang Zhong , Dang Wen Ben Kuang Huo De Jiao Dian Shi , Ti Shi Wen Zi Xiao Shi 。 Yi Qian Yao Shi Xian Zhe Xiao Guo Du Shi Yong JavaScript Lai Kong Zhi Cai Neng Shi Xian , firefox、google chrome Deng Biao Shi Dui Qi Zhi Chi , Wei Du IE Cun Zai Wei He Gan A !

Li Ru : <input id="t1" type="text" placeholder=" Qing Shu Ru Wen Zi " />

Jie Shao Yi Ge Chao Qiang De Rang IE Xia Zhi Chi placeholder De Shu Xing Cha Jian , Tong Shi Ye Jian Rong Qi Ta Bu Zhi Chi placeholder De Zuo Lan Qi , Dai Ma Ru Xia :

Dai Ma Ru Xia :

$(document).ready(function(){
var doc=document,
inputs=doc.getElementsByTagName('input'),
supportPlaceholder='placeholder'in doc.createElement('input'),
placeholder=function(input){
var text=input.getAttribute('placeholder'),
defaultValue=input.defaultValue;
if(defaultValue==''){
input.value=text
}
input.onfocus=function(){
if(input.value===text)
{
this.value=''
}
};
input.onblur=function(){
if(input.value===''){
this.value=text
}
}
};
if(!supportPlaceholder){
for(var i=0,len=inputs.length;i<len;i++){
var input=inputs[i],
text=input.getAttribute('placeholder');
if(input.type==='text'&&text){
placeholder(input)
}
}
}
});

Zhi Jie Ba Dai Ma Fu Zhi Xia Lai , Bao Cun Cheng Yi Ge js Wen Jian Yin Yong Ji Ke , Bu Yong Zai Zuo Ren He Chu Li , Chao Ji Bian Li !

ex : Zhe Yang Zuo De Que Neng Rang IE De Input Xian Shi placeholder Shu Xing , Dan Shi Ru Guo Ye Mian Shang Zhi You Yi Ge input Huan Hao , Ru Guo Shi Duo Ge input, Ru Guo Chu Xian input Mei You Tian Ru Ren He Zhi De Hua , Na Me Ta De Kong input Hui Zi Dong Jiang placeholder De Zhi Tian Jin value Li Mian , Cong Er Fa Sheng Cuo Wu . Li Ru :

Dai Ma Ru Xia :

<input type="text" placeholder=" Shu Ru Shang Pin Bian Ma " name="goodscode" id="goodscode" value="123" />
<input type="text" placeholder=" Shu Ru Shang Pin Ming Cheng " name="goodsname" id="goodsname" value=" Shu Ru Shang Pin Ming Cheng " />

Guan Yu “ Ru He Rang IE Xia Zhi Chi Html5 De placeholder Shu Xing De Cha Jian ” Zhe Pian Wen Zhang Jiu Fen Xiang Dao Zhe Li Liao , Xi Wang Yi Shang Nei Rong Ke Yi Dui Da Jia You Yi Ding De Bang Zhu , Shi Ge Wei Ke Yi Xue Dao Geng Duo Zhi Shi , Ru Guo Jue De Wen Zhang Bu Cuo , Qing Ba Ta Fen Xiang Chu Qu Rang Geng Duo De Ren Kan Dao 。

© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment