Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
模糊后不显示Jquery日期选择器占位符_Jquery_Datepicker - Fatal编程技术网

模糊后不显示Jquery日期选择器占位符

模糊后不显示Jquery日期选择器占位符,jquery,datepicker,Jquery,Datepicker,我有两个简单的文本字段。一个是普通文本,另一个是我用于datepicker的文本。我想清除占位符onfocus并再次显示onblur这是我正在使用的以下代码: $('input,textarea').focus(function(){ $(this).data('placeholder',$(this).attr('placeholder')) console.log($(this).data('placeholder')); $(this).attr('placehol

我有两个简单的文本字段。一个是普通文本,另一个是我用于datepicker的文本。我想清除占位符
onfocus
并再次显示
onblur
这是我正在使用的以下代码:

$('input,textarea').focus(function(){
    $(this).data('placeholder',$(this).attr('placeholder'))
    console.log($(this).data('placeholder'));
    $(this).attr('placeholder','');
});
$('input,textarea').blur(function(){
    console.log("adding "+$(this).data('placeholder'));
    $(this).attr('placeholder',$(this).data('placeholder'));
});
对于普通文本,其工作正常,但对于datepicker文本字段占位符,其不在模糊之后。是否有任何解决方案使日期选择器文本字段的行为类似于简单文本字段


尝试使用

您可以为日期选择器设置一个异常,这样占位符就不会被清除:

$('input:not(#thedate),textarea:not(#thedate)').focus(function(){

由于datepicker,触发了两个焦点事件。第二次触发时,它将清除属性占位符。因此,只需在存储到.data()之前检查属性。像这样的东西应该可以

$('input,textarea').focus(function () {
    if ($(this).prop('placeholder')) {
        $(this).data('placeholder', $(this).prop('placeholder'))
        $(this).prop('placeholder', '');
    }
});
$('input,textarea').blur(function () {
    if (!$(this).prop('placeholder')) {
        $(this).prop('placeholder', $(this).data('placeholder'));
    }
});

这是一个演示

第10行:$(this).data('placeholder',$(this.attr('placeholder'));分号missing@PhilAndelhofs你确定这只是因为
?我不这么认为:-(只是对你的东西的一个评论,现在正在寻找选项。)第二次阅读@Philandelhoff我知道,但谢谢:D仍然在寻找一个简单的解决方案,我认为完全错误,我希望清除datepicker占位符,并像普通文本一样返回。嗯,这是我正在寻找的解决方案。