IE9 不支持。为了在 IE9 中创建相同的效果,我所做的是编写一个 JavaScript 函数来检查是否支持占位符。如果不是,则通过 jQuery 在表单元素字段中显示文本...
/*AN HTML5 INPUT ATTRIBUTE THATS REALLY COOL*/
var placeHolderSupport = ('placeholder' in document.createElement('input'));
/*IF PLACEHOLDER IS NOT SUPPORTED...*/
if(!placeHolderSupport) {
/*GET THE ID OF EACH FORM ELEMENT*/
fname = $('#fname');
femail = $('#femail');
furl = $('#furl');
fcomment = $('#fcomment');
fsubmit = $('#sendbtn');
/*DEFINE DEFAULT VALUES FOR EACH INPUT FIELD*/
fnameval = "Your Full Name";
femailval = "Your E-mail Address - (It will not be shared!)";
furlval = "Your Web Site";
fcommentval = "Your Message";
/*ASSOCIATE THE DEFAULT VALUES TO THE FORM INPUT FIELDS*/
fname.val(fnameval);
femail.val(femailval);
furl.val(furlval);
fcomment.val(fcommentval);
/*CYCLE THROUGH EACH INPUT FIELD TO...*/
$.each([
{selector: fname, mvalue: fnameval},
{selector: femail, mvalue: femailval},
//{selector: furl, mvalue: furlval},
{selector: fcomment,mvalue: fcommentval}
],function(i, obj) {
/*...SHOW OR HIDE DEFAULT VALUES*/
obj.selector.focus(function() {
if(this.value == obj.mvalue) { this.value = ''; };
}).blur(function() {
if(!this.value) { this.value = obj.mvalue;};
});
}