在jquery变量错误中插入大型html标记


Insert Large html markups inside jquery variable error

我正在构建一个网络游戏,但我一直在尝试为jquery-ui dailog框添加html-markup。我目前在chrome中收到Uncaught SyntaxError: Unexpected number错误。我以前尝试过对大数据块使用appendTo方法,但我想知道在jquery变量中可以放置html-elements的数量有限制吗?因为我发现自己每天都要处理这个蚂蚁提示?注意:请在回答之前仔细阅读问题。有没有一种方法可以在jquery variable中存储大块的(html代码/文本)静态或动态?

jquery代码:

 <script>
                    var vari = "<?= $UserSpacesAvA ; ?>";
                    var btn = "<button id='d_pis_btn'>Place in shop</button>";
                    $(vari).appendTo(document).dialog({
                        closeOnEscape: false,
                        modal        : true,
                        draggable    : false,
                        height       : 400,
                        width        : 500,
                        resizable    : false,
                        title        : 'Give Your new <?=ucfirst($morph); ?> A Home!',
                        buttons      : [
                            {
                                text: 'Done!',
                                click: function() {
                                    $(this).dialog("destroy").remove();
                                    }
                             },
                        ],
                        open: function(event, ui) { $(".ui-dialog-titlebar-close").remove(); },
                    });
                    $('.popi select').chosen({});
                    $(btn).appendTo('.set').on("click",function(){
                    });
                    </script>

Php代码:

function UserPlaces($userData,$dataExpected,$type){
    $dat = "<div class='popi' id='pop'><fieldset class='set'><legend>Location:</legend>";
    $x = explode(",",$type);
    foreach($x as $s){
        switch($s){
            case 'rooms':
            // bring out rooms
            $dat .= "<label>Room:</label><select id='d_room_select'>";
                if(count($userData["locations"]['r']) < 1){
                    $dat .= "Insufficient Space";
                }else{
                    $int = 1;
                    foreach($userData["locations"]['r'] as $x){
                        $dat .= "<option value='"$x'">Room Number $int</option>";   
                        $int++;
                    }
                }
            $dat .= "</select><br><br>";
            break;
            case 'shops':
            // bring out shops
            $dat .= "<h4>Is this snake for sale ?</h4><br><label>Shop:</label><select id='d_shop_select'>";
            if(count($userData["locations"]['r']) < 1){
                    $data .= "No Shops";
                }else{
                    $int = 1;
                    foreach($userData["locations"]['s'] as $x){
                        $dat .= "<option value='"$x'">Shop Number $int</option>";   
                        $int++;
                    }
            }
            $dat .= "</select><br><br><label>Price:</label>
            <input id='d_shop_price_snake' name='d_shop_price_snake'><br><br>
            ";
            break;
            case 'shows':
            // bring out shows
            break;
        }
    }
    $dat .= "</fieldset></div>";    
    return $dat;
}

这不能回答您关于限制的问题,但请尝试使用jQuery模板:http://api.jquery.com/category/plugins/templates/