亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

placeholder怎么兼容IE8、9、10???

placeholder怎么兼容IE8、9、10???

就醬ba 2016-06-02 13:48:25
查看完整描述

2 回答

?
一杯2塊的奶茶

TA貢獻226條經驗 獲得超75個贊

.phcolor{?
???color:#999;
}
<input?type="text"?id="uname"?name="uname"?placeholder="請輸入用戶名"/>
<script>
?$(function(){??
??//判斷瀏覽器是否支持placeholder屬性
??supportPlaceholder='placeholder'in?document.createElement('input'),
??placeholder=function(input){
????var?text?=?input.attr('placeholder'),
????defaultValue?=?input.defaultValue;
????if(!defaultValue){
??????input.val(text).addClass("phcolor");
????}
????input.focus(function(){
??????if(input.val()?==?text){
????????$(this).val("");
??????}
????});
????input.blur(function(){
??????if(input.val()?==?""){
????????$(this).val(text).addClass("phcolor");
??????}
????});
????//輸入的字符不為灰色
????input.keydown(function(){
??????$(this).removeClass("phcolor");
????});
??};
??//當瀏覽器不支持placeholder屬性時,調用placeholder函數
??if(!supportPlaceholder){
????$('input').each(function(){
??????text?=?$(this).attr("placeholder");
??????if($(this).attr("type")?==?"text"){
????????placeholder($(this));
??????}
????});
??}
});
</script>

ie10會有點小問題,其他ie沒問題

查看完整回答
反對 回復 2016-06-02
?
慕粉3207054

TA貢獻3條經驗 獲得超0個贊

解決IE8的兼容性問題
<script?type="text/javascript">??
??if(?!('placeholder'?in?document.createElement('input'))?){???
????$('input[placeholder],textarea[placeholder]').each(function(){???
??????var?that?=?$(this),???
??????text=?that.attr('placeholder');???
??????if(that.val()===""){???
????????that.val(text).addClass('placeholder');???
??????}???
??????that.focus(function(){???
????????if(that.val()===text){???
??????????that.val("").removeClass('placeholder');???
????????}???
??????})???
??????.blur(function(){???
????????if(that.val()===""){???
??????????that.val(text).addClass('placeholder');???
????????}???
??????})???
??????.closest('form').submit(function(){???
????????if(that.val()?===?text){???
??????????that.val('');???
????????}???
??????});???
????});???
??}??
</script>


查看完整回答
反對 回復 2016-06-02
  • 就醬ba
    就醬ba
    有沒有可以直接樣式控制的方法??
  • 2 回答
  • 1 關注
  • 2219 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號