简体   繁体   English

JavaScript 用于比较组合日期和日期选择器日期

[英]JavaScript for comparing combo date with date picker date

I want to select the date in combo box which is less-than or equal to date selected in date picker.我想要 select 组合框中的日期小于或等于日期选择器中选择的日期。 I am using this code.我正在使用这段代码。 Note combo box contains the dates from database in an array.注意组合框包含数组中数据库中的日期。

But its not working as per my requirement.但它没有按照我的要求工作。

function copytxt(){
        var w = document.getElementById("dateoil").value;
        document.getElementById("cb1").value <= w;}

If "dateoil" represents date picker and "cb1" represents combo box.如果“dateoil”代表日期选择器,“cb1”代表组合框。 Then from what I have understood, this might be helpful:然后据我了解,这可能会有所帮助:

function copyText() {
        var dp = document.getElementById("dateoil").value;
        var cb = document.getElementById("cb1").value;
        if(cb <= dp) {
           cb = dp;
        }
   }

Assuming the combo box receives the data from database and its an array of positive decimal values.假设组合框从数据库接收数据及其正十进制值数组。 Then this could be one of the ways to achieve the desired output.那么这可能是实现所需 output 的方法之一。

function setValue() {
        var dp = document.getElementById("dateoil");
        var cb = document.getElementById("cb1").value;
        var comboValues = [];
        for (var i = 0; i < dp.length; i++){ 
            if(dp[i].value <= cb){
              comboValues.push(parseFloat(dp[i].value));
            }
        }
        dp.value = comboValues.sort().pop();
   }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM