-1

I'm trying to make a JavaScript function to validate the month and year from a field. The format of the date on the field is mm/yyyy and the function that validates it's the one below:

function validateVencimento(){
    var valid = true;
    var currentTime = new Date();
    var actualMonth = currentTime.getMonth() + 1;
    var actualYear = currentTime.getFullYear();
    vencimento = vencimento.replace('///g', '');

    var month = parseInt(vencimento.substring(0, 2),10);
    var year  = parseInt(vencimento.substring(2, 6),10);

    if((month < 1) || (month > 12)) valid = false;
    if((year < actualYear)) valid = false;
    if((year < actualYear) && (month < actualMonth)) valid = false;

    if(valid == false){
        vencimento.addClass("error");
        vencimentoInfo.text("A validade do cartao esta invalida!");
        vencimentoInfo.addClass("error");
        return false;
    }

    else{
        vencimento.removeClass("error");
        vencimentoInfo.text("");
        vencimentoInfo.removeClass("error");
        return true;
    }
}

After i enter the date on the field i call the function above on blur, but the Chrome console returns the error Uncaught TypeError: Object # has no method 'replace'.


jquery modal duplication on single ajax page dashboard

I have an issue where I have 5 jquery dialog in a certain ajax request. This page doesn't reload, and relies entirely on ajax. Once this certain ajax request loads with the 5 dialogs, they are initialized, and the plugin adds the necessary markup at the bottom of the page for the dialog . I leave that page via ajax to go to another ajax request. That html generated from the modals are still on the page. If I go back to the page that has these 5 dialogs again, it adds another 5 modals to the html at the bottom, so now that makes 10. Is there a good way to remove these modals when navigating ajax pages, or do I have to keep track of it? There are some dialogs that are global, and are used by every ajax request, so a global delete wont work either.

4

1 回答 1

3

看起来您vencimento同时用作字符串和 jQuery 对象。你不能那样做。也许vencimentoText像这样创建一个新变量:

var vencimentoText = vencimento.val();

然后vencimentoText在您当前将其用作字符串的任何地方使用(例如,with replace,substring等,但不是addClass等)

于 2013-04-28T22:12:59.203 回答