我怎样才能得到动态创建的div的这个游戏?

时间:2018-03-23 17:01:18

标签: javascript

我正试图从我的按钮获取一个特定的gameId和.text类,我已经尝试了下面的代码,但它似乎只给我一个未定义的答案。我不知道它是否与我运行的地方或其他地方有关。任何帮助将不胜感激!这段代码在一个循环中,根据JSON中有多少个来附加这些div。

$('.wrapper').append('\
    <div id="'+ gameId +'" class="main-wrapper col-lg-6 col-md-6 col-sm-12">\
        <div class="game-cards">\
            <div class="chart-container">\
                <canvas id="'+ homeTeam +'" width="500" height="500"></canvas>\
            </div>\
            <div class="right-info">\
                <h4>' + awayTeam + '<br>' + " @ " + '<br>' + homeTeam +'</h4>\
                <h5 id="time-channel">'+ gameDate +' @ ' + gameTime  + ' CT' + '<br>' + ' On ' + network +'</h5>\
            <div class="total-points-live">\
                <h5>Total Points Bet</h5>\
                <h5 class="total-points" id="point-total">'+ totalPoints +'</h5>\
                <p>'+ awayTeam + " " + awayLine +'</p>\
                <input class="bet-input-away" id="testBox" min="1" step="1" onkeypress="return event.charCode >= 48 && event.charCode <= 57" title="Numbers only" data-away-id="'+ awayId +'" data-team-type="'+ awayTeam +'" type="number" min="0" pattern="[1-9]*" name="betAmountAway" placeholder="Wager Amount">\
                <p>'+ homeTeam + " " + homeLine +'</p>\
                <input class="bet-input-home" min="1" step="1" onkeypress="return event.charCode >= 48 && event.charCode <= 57" title="Numbers only" data-home-id="'+ homeId +'" data-team-type="'+ homeTeam +'" type="number" min="0" pattern="[1-9]*" name="betAmountHome" placeholder="Wager Amount">\
                <div class="wrap">\
                    <div id="capture" class="box">\
                         <button id="'+ gameId +'" class="text" data-button-id="'+ gameId +'">Click</button>\
                    </div>\
                    <div class="box paste"></div>\
                </div>\
                <p class="bet-button" gameid="'+ gameId +'">Click To Place Bet</p>\
            </div>\
        </div>\
    </div>\
        ');

    var self = $(this);
    var gameId = self.attr('gameid');
    var awayId = $('#' + gameId + '.text').data('button-id');

    console.log(gameId);

    console.log(awayId);

        $('.text').click(function(){
            alert('clicked');
            allowTaint: true,
            html2canvas($("#5995")[0]).then(function(canvas) {
            $("#hello").append(canvas);
            });
        });

0 个答案:

没有答案