开发者

Declare javascript function, jQuery

开发者 https://www.devze.com 2023-01-16 14:29 出处:网络
in my main js file where I put all my jQuery stuff I have following new funcitons: function getDate(){

in my main js file where I put all my jQuery stuff I have following new funcitons:

function getDate(){
    var currentTime = new Date();
    var month = currentTime.getMonth() + 1;
    var day = currentTime.getDate();
    var year = currentTime.getFullYear();
    return  day"."+month+"."+year;
}

function getTime(){
    var currentTime = new Date();
    var hours = currentTime.getHours();
    var minutes = c开发者_运维技巧urrentTime.getMinutes();
    if (minutes < 10){
        minutes = "0" + minutes;
    }

    return  hours":"+minutes;
}

...but when I have these functions added to my main js file the jquery part does not work anymore. any ideas?


Well for starters, you were concatenating strings wrongly.

function getDate(){
    var currentTime = new Date();
    var month = currentTime.getMonth() + 1;
    var day = currentTime.getDate();
    var year = currentTime.getFullYear();
    return day + "." + month + "." + year;
}

function getTime(){
    var currentTime = new Date();
    var hours = currentTime.getHours();
    var minutes = currentTime.getMinutes();
    if (minutes < 10){
        minutes = "0" + minutes;
    }

    return hours + ":" + minutes;
}


Missing a +:

return  day"."+month+"."+year;

Here as well:

return  hours":"+minutes;

Syntax errors will prevent the entire file from being executed. You should really look at your browser's error console before posting.


It probably breaks it because of a syntax error in your functions:

You are missing the '+' in both your returns after 'day' and 'hours'.

return  day"."+month+"."+year; 

should be

return  day+"."+month+"."+year;

and

return  hours":"+minutes;

should be

return  hours+":"+minutes;
0

精彩评论

暂无评论...
验证码 换一张
取 消