1
 <script>
    function numeri_validator(t) {
        var patt = /(\d*)\.{1}(\d{0,2})/;
        var donepatt = /^(\d*)\.{1}(\d{2})$/;
        var str = t.value;
        var result;
        if (!str.match(donepatt)) {
            result = str.match(patt);
            if (result != null) {
                t.value = t.value.replace(/[^\d]/gi, '');
                str = result[1] + '.' + result[2];
                t.value = str;
            } else {
                if (t.value.match(/[^\d]/gi))
                    t.value = t.value.replace(/[^\d]/gi, '');
            }
        }



       //get the date
            var val1 = document.getElementById("cost" + 1).value;
            var val2 = document.getElementById("cost" + 2).value;

       //Get date
            var date = document.getElementById("Label1").innerText;

        //format time
            var timeIn = val1.replace('.', ':');
            var timeOut = val2.replace('.', ':');

        //Concat time with date
            var timeinDate = date + " " + timeIn;
            var timeoutDate = date + " " + timeOut;

        //calculate time difference
            var nDifference = Math.abs(new Date(timeoutDate) - new Date(timeinDate));

            var one_hours = 1000 * 60 * 60;
            var hours = (Math.floor(nDifference / one_hours));

            var diff = nDifference % one_hours;

            var one_min = 1000 * 60;

            var diffmin = Math.round(diff / one_min);

            document.getElementById("datelabel").innerText = hours + "." + diffmin;

            document.getElementById("total").value = hours + "." + diffmin;

这个计算两次之间差异的函数工作正常,但仅在其他浏览器的 Chrome 中工作是:

document.getElementById("total").value=NaN:NaN

请帮我。

4

2 回答 2

0

问题应该是因为您的代码中的这一部分。.innerText.

var date = document.getElementById("Label1").innerText;

.innerText在 Mozilla 中不起作用。.textContent改为使用

var date = document.getElementById("Label1").textContent;
于 2013-10-18T11:42:11.140 回答
0

我通过更改日期格式解决了这个问题。实际上这个问题与 new Date()

新的日期格式应该是

new Date('2013/10/19 12:00')// 不是 2013-10-19

现在适用于所有浏览器

谢谢

于 2013-10-19T20:47:39.827 回答