event.target无法在移动设备上运行

时间:2015-05-19 04:47:40

标签: javascript forms meteor

我正在使用表单来收集数据。一旦用户点击提交,则假设更新用户和问题文档。该功能适用​​于桌面,但不适用于移动设备。

当我对值answerwager进行硬编码时,它对两者都有效。问题似乎是event.target.wager.value。我尝试将值放在Session中,并尝试将它们转换为int和字符串。

以下代码位于Main.js

Template.questionCard.events({
    'submit form': function(event) {
        event.preventDefault();
        var questionId = this._id;
        var currentUser = Meteor.userId();

        // Collects the data from the form when submitted.
        // var answer = event.target.play.value;
        // var wager = event.target.wager.value;

    var answer = "Run";
    var wager = 5000;

    //Add user data to question
    Meteor.call('questionAnswered', currentUser, questionId, answer, wager);

    console.log('User: ' + currentUser + ' answered question ' + questionId + ' -- ' + answer + ' ' + wager);
}

以下是名为questionAnswered的方法。

'questionAnswered' : function( user, questionId, answer, wager){
    QuestionList.update(questionId, {$push: {usersAnswered: user}});
    console.log(user + " answered " + questionId)
    console.log("User wagered " + wager + " coins." );
    Meteor.users.update( {_id: user}, {$inc: { "profile.coins": -wager}} );


    //Add question, wager and answer to the user's account.
    Meteor.users.update( { _id: user}, {$push: {questionAnswered: { questionId: questionId, 
        wager: wager, answered: answer}}});
    console.log(user + " answered " + answer);

    //Update the question with the users answer and wager.
    if (answer == "Run"){
        QuestionList.update(questionId, {$push: { usersRun: {userID: user, amount: wager } }});
    } else if (answer == "Pass"){
        QuestionList.update(questionId, {$push: {usersPass: {userID: user, amount: wager}}});
    } else if (answer == "Fumble"){
        QuestionList.update(questionId, {$push: {usersFumble: {userID: user, amount: wager}}});
    } else if (answer == "Interception"){
        QuestionList.update(questionId, {$push: {usersInterception: {userID: user, amount: wager}}});
    }

2 个答案:

答案 0 :(得分:0)

Jimmy Mian-Guan Lim here发表评论。使用无线电输入和组名称查找选中的选项。然后返回值。

    var answer = template.find('input:radio[name=play]:checked').value;
    var wager = template.find('input:radio[name=wager]:checked').value;

答案 1 :(得分:0)

请尝试使用/^[A-Z]{2}\d{8}$/

流星似乎有点好用。