【问题标题】:How to change the color of a button when a date value changes and also when a textbox value changes?当日期值更改以及文本框值更改时如何更改按钮的颜色?
【发布时间】:2015-02-23 07:06:05
【问题描述】:

我有一个视图,其中包含多个文本框和一个带有灰色按钮的日期选择器。当文本框和日期选择器的值发生变化时,按钮的颜色变为红色,如果我用预览替换输入的新值,它再次变为灰色。

我的代码(如下)在文本框上运行良好,但在日期选择器上运行良好:

$(".class Selector").each(function(){
  $(this).on('change blur keyup',function(){
    if(oldvalue of textbox1!=newvalue of textbox1){
      $("#button id ").css('backgroundcolor','red')
    }
    else if(oldvalue of textbox2!=newvalue of textbox2){
      $("#button id ").css('backgroundcolor','red')
     }
    else if(oldvalue of datepicker !=newvalue of datepicker){
      $("#button id ").css('backgroundcolor','red')
     }
    else {
      $("#button id ").css('backgroundcolor','gray')
    }
  });
});

我的代码在文本框值的情况下运行,但它不适用于 datepicker 情况

在这种情况下,.on 首先触发,而我想在更改时触发日期选择器。当我点击日期选择器文本框时,我总是得到未定义的新日期。

请帮忙。谢谢。

【问题讨论】:

  • 查看发布/订阅和自定义事件。你的代码很快就会变得简单很多。
  • 任何代码 Chris Caviness
  • 能提供jsfiddle吗?
  • 提供演示所需的最少标记和代码。

标签: jquery html css datepicker


【解决方案1】:

使用 JQuery UI 日期选择器。 在 JQuery UI 中 datepicker 有一个函数,名称为 onSelect,在这个函数下你可以添加你的代码。了解更多请点击这里。enter link description here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-09
    • 1970-01-01
    • 1970-01-01
    • 2017-03-30
    • 2012-06-25
    • 1970-01-01
    相关资源
    最近更新 更多