主頁(yè) > 知識(shí)庫(kù) > HTML 5 input placeholder 屬性如何完美兼任ie

HTML 5 input placeholder 屬性如何完美兼任ie

熱門標(biāo)簽:百度競(jìng)價(jià)點(diǎn)擊價(jià)格的計(jì)算公式 檢查注冊(cè)表項(xiàng) 美圖手機(jī) 使用U盤裝系統(tǒng) 智能手機(jī) 網(wǎng)站建設(shè) 硅谷的囚徒呼叫中心 阿里云
記得引用jquery 類庫(kù)

復(fù)制代碼
代碼如下:

$(document).ready(function () {
if ($.browser.msie)
$("input:text,input:password").each(function () {
var $placeholder = $(this).attr("placeholder");
var $width = $(this).css("width");
var $id = $(this).attr("id");
var $height = parseInt($(this).css("height")) + 6 + "px";
var $fontSize = $(this).css("font-size");
var $fontWeight = $(this).css("font-weight");
var $lineHeight = $height;
if ($(this).css("line-height") != "normal") {
$lineHeight = parseInt($(this).css("line-height")) + 6 + "px";
}
if ($placeholder != undefined) {
$(this).after("<span class=\"placeholder ph_" + $id + "\" style=\"width:" + $width + ";line-height:" + $lineHeight + ";height:" + $height + ";font-weight:" + $fontWeight + ";margin-left:-" + $width + ";font-size:" + $fontSize + "\">" + $placeholder + "</span>");
}
$(this).bind("keyup", function () {
if ($(this).val() == "") {
$(this).parent().find(".ph_" + $id).css("display", "inline-block");
}
else {
$(this).parent().find(".ph_" + $id).css("display", "none");
}
});
});
$(".placeholder").live("click", function () {
$(this).prev().focus();
});
});

頁(yè)面調(diào)用

復(fù)制代碼
代碼如下:

<input id="n1" type="text" placeholder="我是提示內(nèi)容正常" />

<input id="n2" type="text" placeholder="我是提示內(nèi)容寬高" style="width:100px;height:100px;" />

<input id="n3" type="text" placeholder="我是提示內(nèi)容我有其他樣式" / style="width:300px;height:40px;font-weight:bold;">

<input id="n4" type="text" placeholder="還可以嘗試下其他的" />


樣式

復(fù)制代碼
代碼如下:

<style type="text/css">
.placeholder {display:inline-block;color:gray;vertical-align:top;overflow:hidden;}
</style>

標(biāo)簽:通遼 煙臺(tái) 湖北 懷化 黃山 賀州 湘潭 山南

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《HTML 5 input placeholder 屬性如何完美兼任ie》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266