placeholder在不支持html5的低版本的瀏覽器中,placeholder屬性是無效的尽楔,ie9及以下的ie瀏覽器不兼該屬性。
網(wǎng)上找到了解決辦法:
?????? 解決思路是用input的value值來模擬placeholder的效果第练,包括input類型為password時(shí)的替換阔馋,但效果和placeholder稍有差異。
具體做法:引入jquery.placeholder.js文件娇掏,調(diào)用placeholder()方法呕寝。
文件下載地址:https://github.com/shwoodard/jquery.placeholder.js。
補(bǔ)充:在項(xiàng)目中應(yīng)用的過程中發(fā)現(xiàn)婴梧,當(dāng)input類型為password時(shí)下梢,密碼的input框$('input')調(diào)用placeholder()方法后獲取到的value值為placeholder中的內(nèi)容,后來仔細(xì)看了jquery.placeholder.js文件并結(jié)合項(xiàng)目發(fā)現(xiàn)志秃,該方法中(type='password'時(shí)才會(huì)創(chuàng)建)創(chuàng)建的input( class為placeholder_el )和原本頁(yè)面中存在的input(placeholder)有不同的class(方法中以標(biāo)明),方法中在提交表單時(shí)(submit方法)將創(chuàng)建的input移除怔球。但是,要注意前提要觸發(fā)submit方法浮还,否則需要在提交表單之前手動(dòng)移創(chuàng)建的input($('input.placeholder_el').remove();)竟坛。