2017-04-15 128 views
0

夥計們我已經閱讀了關於該主題的所有內容,但我仍然無法弄清楚爲什麼我的佔位符未顯示。希望你能分享你的專業知識,並告訴我做錯了什麼。佔位符不顯示

<input type="text" name="search" class="input-block-level search-query" placeholder="Enter your name" required=""> 

這只是沒有顯示在任何瀏覽器。感謝提前!

+1

您使用的是什麼瀏覽器?請記住,某些瀏覽器(如IE6-9,Opera 10.1和FF <4.0)不支持「placeholder」屬性:http://caniuse.com/#feat=input-placeholder – Terry

回答

-1

我發現這個鏈接,它會給我們一個關於如何修復佔位符問題的好主意,它會使用jquery,這將是一個很好的解決方案。 http://www.hagenburger.net/BLOG/HTML5-Input-Placeholder-Fix-With-jQuery.html 這裏是全jQuery代碼 //在MIT許可下發布:http://www.opensource.org/licenses/mit-license.php

$('[placeholder]').focus(function() { 
var input = $(this); 
if (input.val() == input.attr('placeholder')) { 
input.val(''); 
input.removeClass('placeholder'); } 
}).blur(function() { 
var input = $(this); 
if (input.val() == '' || input.val() == input.attr('placeholder')) { 
input.addClass('placeholder'); 
input.val(input.attr('placeholder')); 
} 
}).blur().parents('form').submit(function() { 
$(this).find('[placeholder]').each(function() { 
var input = $(this); 
if (input.val() == input.attr('placeholder')) { 
input.val(''); 
} 
}) 
}); 
0

您可以嘗試使用此代碼到你的佔位符顯示在此輸入。

$(document).ready(function() { 
 
    function add() {if($(this).val() == ''){$(this).val($(this).attr('placeholder')).addClass('placeholder');}} 
 
    function remove() {if($(this).val() == $(this).attr('placeholder')){$(this).val('').removeClass('placeholder');}} 
 
    if (!('placeholder' in $('<input>')[0])) { 
 
     $('input[placeholder]').blur(add).focus(remove).each(add); 
 
     $('div').submit(function(){$(this).find('input[placeholder]').each(remove);}); 
 
    } 
 
});
<div> 
 
<input type="text" name="search" class="input-block-level search-query" placeholder="Enter your name" required> 
 
</div>