我知道这个问题已经在这里问了很多时间,但我仍然无法找到解决我的问题的方法。我有一个textarea
在我的asp.net mvc应用程序中有一个占位符。Internet Explorer 8&9中的占位符
<textarea placeholder="Write Query..." maxlength="1000"></textarea>
现在的Internet Explorer 8 & 9不支持占位符属性,因此我需要一些解决方法,我有搜索结果和谷歌,发现各种的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("");
}
})
});
}
});
我认为您需要区分您的问题与其他人,否则这将会以重复的方式关闭 – TankorSmash