[英]Placeholder in Internet Explorer 8 & 9
Guys I know this question has been asked here many time but still I wasn't able to find a solution to my problem. 伙计们,我知道这个问题已经在这里问过很多次了,但仍然找不到我的问题的解决方案。 I have a
textarea
in my asp.net mvc application which has a placeholder in it. 我的asp.net mvc应用程序中有一个
textarea
,其中有一个占位符。
<textarea placeholder="Write Query..." maxlength="1000"></textarea>
Now Internet Explorer 8 & 9 doesn't support the placeholder property so I need some workaround for it, I have search here and google and found various javascripts but unfortunately none of those worked. 现在,Internet Explorer 8和9不支持占位符属性,因此我需要一些解决方法,我在这里和google上进行了搜索,发现了各种JavaScript,但不幸的是这些都不起作用。 Although some worked (as the showed the placeholder text) but the text didn't disappear on writing in the
textArea
尽管有些有效(如显示的占位符文本),但在
textArea
书写时,该文本并未消失
Two of those scripts (that worked half right) are these : 这些脚本中的两个(正确运行一半)是:
$(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(''); });
});
}
});
Second : 第二:
$(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("");
}
})
});
}
});
try to this alternative 尝试这种替代
https://github.com/parndt/jquery-html5-placeholder-shim/ https://github.com/parndt/jquery-html5-placeholder-shim/
i think it's can manage by meta tag 我认为可以通过meta标签进行管理
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.