0

我正在尝试通过 jQuery 的 ajax 函数提交表单,如下所示:

$("form#game_submit").submit(function(){   
var away = $("#away_score").val();
var home = $("#home_score").val();
var game = "1148";
var home_team = "Cleveland Cavaliers";
var away_team = "Orlando Magic";
var home_short = "Cavaliers";
var away_short = "Magic";
var date = "463";
var league = "nba";

if(away != home
&& is_numeric(home)
&& is_numeric(away))
{        
    $.ajax({  
        type: "POST",  
        url: "/model/ajax/game_predictions_submit.php",  
        data: ({
            away_score: away,
            home_score: home,
            away: away_team, 
            home: home_team, 
            game: game,
            date: date,
            league: league
        }),
        success: function()
        {
            if(away > home)
            {
                var winner = away_team;
                var loser = home_team;

                var winner_short = away_short;
                var loser_short = home_short;

                var win_score = away;
                var lose_score = home;
            }

            if(home > away)
            {
                var winner = home_team;
                var loser = away_team;

                var winner_short = home_short;
                var loser_short = away_short;

                var win_score = home;
                var lose_score = away;
            }

            if(league == "ncaa")
            {
                var win_img = winner_short;
                var lose_img = loser_short;
            }

            if(league != "ncaa")
            {
                var win_img = winner;
                var lose_img = loser;
            }

            alert(hi);
            $('#away_score').attr('readonly', true);
            $('#home_score').attr('readonly', true);
            return false;
        } 
    });   
}
return false;
});

HTML如下:

<form id='game_submit'>
    <input type='text' name='away_team' maxlength='3' id='home_score' class='bar' style='width:30px;top:0px;' autocomplete='off'  value='0'/>
    <input type='text' name='away_team' maxlength='3' id='away_score' class='bar' style='width:30px;top:0px;' autocomplete='off'  value='0'/>

    <button class='minimal' id='game_submit_button' style='float:right;'>Save</button>
</form>

我试图查看 Chrome 的 javascript 控制台中的问题,但它并没有给我带来任何错误。可以在这里找到一个工作示例

4

1 回答 1

0

尝试使用 not isNaN (不是数字)

if(away != home
&& !isNaN(home)
&& !isNaN(away))
{ 
于 2013-02-26T18:18:50.413 回答