Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.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
Javascript 在Edge和Chrome中使用标准日期选择器时,更改我的输入字段的文本颜色_Javascript_Jquery - Fatal编程技术网

Javascript 在Edge和Chrome中使用标准日期选择器时,更改我的输入字段的文本颜色

Javascript 在Edge和Chrome中使用标准日期选择器时,更改我的输入字段的文本颜色,javascript,jquery,Javascript,Jquery,当我从Edge和Chrome中的标准日期选择器中进行选择时,我想更改表单上日期字段的背景 我的jquery $(document).ready(function () { $(":input").change(function () { toggleEmptyInputs($(this)); }); }); 我的日期字段是: <input type="date" name="Birthday" class="date mandatory empty valid

当我从Edge和Chrome中的标准日期选择器中进行选择时,我想更改表单上日期字段的背景

我的jquery

$(document).ready(function () {
   $(":input").change(function () {
        toggleEmptyInputs($(this));
   });
});
我的日期字段是:

<input type="date" name="Birthday" class="date mandatory empty validationerror" id="i105">
但这不起作用,并且在firefox中也会产生错误,如
uncaughttypeerror:$(…)。datepicker
不是一个函数

提前谢谢你的帮助

切换功能是

function toggleEmptyInputs(inputElement) {
    if (inputElement.val()) {
        inputElement.removeClass("empty");
        inputElement.closest(".col").removeClass("hidelabel");
    } else {
        inputElement.addClass("empty");
        inputElement.closest(".col").addClass("hidelabel");
    }
}
在所有其他领域都适用

由于css中的
.empty:after{content:“empty”}
,小提琴工作正常 所以我将把它合并到我的removeClass函数中

感谢Scimonster的帮助:“我想在选择时更改表单上日期字段的背景”您只需添加一个类即可

示例:使用
colorme
class

$(document).ready(function() {
  $("input[type='date']").change(function() {
    console.log('got here');
    toggleEmptyInputs($(this));
  });
});

function toggleEmptyInputs(inputElement) {
  var hasValue = !!inputElement.val();
  inputElement.toggleClass("empty", !hasValue).toggleClass('colorme', hasValue);
  inputElement.closest(".col").toggleClass("hidelabel", hasValue);
}
CSS:

我改变了主意

$(document).ready(function() 


如果
$(…).datepicker不是一个函数。
您可能没有包含jQuery UI。你甚至可能不需要它。我只是尝试了.datepicker,因为我不知道还能用什么。datepicker响应
更改
事件,至少在我的Chrome浏览器中是这样。可能是代码的其他部分导致了问题。你能包括你的
toggleEmptyInputs
功能吗?刚刚添加了切换功能。jquery onchange根本没有执行似乎对我有效。不幸的是,当我单击datepicker选择一个日期时,onchange没有被触发
input.colorme {
  color: lime;
  background-color: pink;
}
$(document).ready(function() 
 $(window).load(function ()