在 Edge 和 Chrome 中使用标准日期选取器时,更改输入字段的文本颜色
Change the text color of my input field when using the standard datepicker in Edge and Chrome
我想
在 Edge 和 Chrome 中的标准日期选择器中进行选择时更改表单上日期字段的背景。
我的查询
$(document).ready(function () {
$(":input").change(function () {
toggleEmptyInputs($(this));
});
});
我的日期字段是:
<input type="date" name="Birthday" class="date mandatory empty validationerror" id="i105">
ID是自动制作的,可以针对不同的形式进行更改。所以我需要使用名称或.....
我真正想要的是当我使用删除类中的空部分datepicker
时(基本上这就是 toggleEmptyInputs
函数在我的 jquery 中所做的)。
我尝试使用:
$(":input").datepicker({
onSelect: function() {
toggleEmptyInputs($(this));
}
});
但这不起作用,并且在 Firefox 中也会产生错误,因为Uncaught TypeError: $(...).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"}
所以我要把它合并到我的 删除类 函数
谢谢科学怪物
为了方便:"我想在选择时更改表单上日期字段的背景",您只需添加一个类即可。
示例:使用colorme
类
$(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:
input.colorme {
color: lime;
background-color: pink;
}
我已经更改了
$(document).ready(function()
自
$(window).load(function ()
相关文章:
- 将输入字段中的文本提交到我的数据库,同时将其添加到我的列表中
- 而循环只设置php中输入字段中的第一个值
- 在输入字段中将最小金额设置为
- 如何在输入字段中的按钮的帮助下打开日历,该字段的类型为“=”;日期”;
- 如何在HTML输入字段中添加不可删除的后缀
- 互斥单选按钮和相应的输入字段
- 在IE9中的输入字段中输入焦点最近按钮
- 选中单选框时将属性添加到输入字段
- 当设置addFromAutocompleteOnly时,剩余文本将保留在输入字段中
- 我如何在数字插入中使用逗号,这样它就不会'不要破坏我的输入字段
- 在输入字段上有两个函数调用,一个在Blur上,一个不在Angular中
- 输入字段将't获取更新的值
- 如何选择多个输入字段并删除所需的属性
- 输入字段,只接受0到12之间的数字
- 单击鼠标,用MySQL数据填充html表单输入字段
- 使用jquery将输入字段转换为文本
- Model中的Typeahead返回空值以形成输入字段
- 如何从查询字符串中的输入字段发回文本
- 如何验证日期、月份和日期的3个独立输入字段;年使用jquery或javascript
- 将值传递给jquery创建的输入字段