3 回答

TA貢獻10條經驗 獲得超11個贊
檢測瀏覽器是否支持placeholder屬性
function hasPlaceholderSupport() {? ? ?
?return 'placeholder' in document.createElement('input');? ? ?
} ? ?
我記得我一個同學是這樣解決的,用一個插件
$(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)
? ? ? ? ?}
? ? ?}
?}
});
這個復制粘貼保存下來,保存成一個JS文件再導入

TA貢獻29條經驗 獲得超4個贊
如果我沒理解錯的話你應該想寫這個,我的ie是可以的
<form?action="#"?method="post"> ????<input?type="text"?placeholder="請輸入用戶名"?/> </form>
添加回答
舉報