Javascript 文本区域的Internet Explorer占位符
我的应用程序需要一个文本字段和一个文本区域字段的占位符。我知道Internet Explorer不支持占位符。我环顾四周,发现了一些仅适用于文本字段的回退代码。我怎样才能让这个工作的文本区也 代码: HTML:Javascript 文本区域的Internet Explorer占位符,javascript,jquery,html,Javascript,Jquery,Html,我的应用程序需要一个文本字段和一个文本区域字段的占位符。我知道Internet Explorer不支持占位符。我环顾四周,发现了一些仅适用于文本字段的回退代码。我怎样才能让这个工作的文本区也 代码: HTML: 它正在使用,请将其更改为同时使用textarea $(':text') 应该是 $(':text, textarea') 或供使用 看起来您需要将:text替换为:text,textarea将$(':text')更改为$('input[type=“text”],textare
它正在使用,请将其更改为同时使用textarea
$(':text')
应该是
$(':text, textarea')
或供使用
看起来您需要将
:text
替换为:text,textarea将$(':text')
更改为$('input[type=“text”],textarea')
或者,此现有jQuery插件:
适用于文本区域和多种类型的输入字段,包括密码字段
<script type="text/javascript">
$(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(''); });
});
}
});
</script>
$(函数(){
如果(!$.support.placeholder){
var active=document.activeElement;
$('input[type=“text”],textarea')。焦点(函数(){
if($(this.attr('placeholder')!=''&$(this.val()==$(this.attr('placeholder')){
$(this.val(“”).removeClass('haspocholder');
}
}).blur(函数(){
if($(this.attr('placeholder')!=''&($(this.val()=''this.val()=''(this.val()==$(this.attr('placeholder')){
$(this.val($(this.attr('placeholder')).addClass('haspholder');
}
});
$('input[type=“text”],textarea').blur();
$(活动).focus();
$('form')。提交(函数(){
$(this.find('.haspholder').each(function(){$(this.val('');});
});
}
});
NITPICK:不要将占位符用作标记。
$(':text, textarea')
$('input[type=text], textarea')
<script type="text/javascript">
$(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(''); });
});
}
});
</script>