[英]Placeholder in Internet Explorer 8 & 9
伙計們,我知道這個問題已經在這里問過很多次了,但仍然找不到我的問題的解決方案。 我的asp.net mvc應用程序中有一個textarea
,其中有一個占位符。
<textarea placeholder="Write Query..." maxlength="1000"></textarea>
現在,Internet Explorer 8和9不支持占位符屬性,因此我需要一些解決方法,我在這里和google上進行了搜索,發現了各種JavaScript,但不幸的是這些都不起作用。 盡管有些有效(如顯示的占位符文本),但在textArea
書寫時,該文本並未消失
這些腳本中的兩個(正確運行一半)是:
$(function () {
if (!$.support.placeholder) {
var active = document.activeElement;
$('input[type="text"], textarea').focus(function () {
if ($(this).attr('placeholder') != '' && $(this).val() == $(this).attr('placeholder')) {
$(this).val('').removeClass('hasPlaceholder');
}
}).blur(function () {
if ($(this).attr('placeholder') != '' && ($(this).val() == '' || $(this).val() == $(this).attr('placeholder'))) {
$(this).val($(this).attr('placeholder')).addClass('hasPlaceholder');
}
});
$('input[type="text"], textarea').blur();
$(active).focus();
$('form').submit(function () {
$(this).find('.hasPlaceholder').each(function () { $(this).val(''); });
});
}
});
第二:
$(function () {
if ($.browser.msie && $.browser.version <= 9) {
$("[placeholder]").focus(function () {
if ($(this).val() == $(this).attr("placeholder")) $(this).val("");
}).blur(function () {
if ($(this).val() == "") $(this).val($(this).attr("placeholder"));
}).blur();
$("[placeholder]").parents("form").submit(function () {
$(this).find('[placeholder]').each(function () {
if ($(this).val() == $(this).attr("placeholder")) {
$(this).val("");
}
})
});
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.