javascript - 如何通过创建div来隐藏JSON数据

标签 javascript jquery html

为了隐藏 JSON 数据(以便稍后可以淡入),我通过创建名为“loading”的 div 来修改 a1.start 函数,但在 Chrome 的 Javascript 控制台中,有

Uncaught SyntaxError: Unexpected token ILLEGAL

在 HTML 中:a1.start($("#cakeHook"),"a1data.json");

<!doctype html>
<html>
    <head>
    <style>
    </style>
    <title>Cake Baby Bakery</title>
    <script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
    <script src="a1.js"></script>
    <link href="css/bootstrap.css" rel="stylesheet"/>
    <link href="css/basica1.css" rel="stylesheet"/>
    </head>
    <body>  
        <div id="cakeHook" ></div>
        <script>

        a1.start($("#cakeHook"),"a1data.json");

        </script>   
    </body>
</html>

a1.start

a1.start = function(hookElementSelection, dataurlForJsonFile) {

jQuery('<div/>', {
id: 'loading',
text: 'Loading...'
}).appendTo('hookElementSelection');

$('hookElementSelection).hide();

    a1.products = {};
    a1.recipes = {};
    a1.suppliers = {};
    a1.bakedRecipes = [];

    //make an ajax call and wait for success
    $.ajax({url:dataurlForJsonFile}).success(function(data) {

        //get the recipe data
        parseJSONData(data);

        //put the recipes on the page
        $.each(a1.recipes, function(i, recipe) {
            recipe.render(hookElementSelection);
        });
        renderCalculator(hookElementSelection); //add in the final calculation logic
    });
};

最佳答案

当您尝试使用变量时,您正在使用字符串:

.appendTo('hookElementSelection')

应该是:

.appendTo(hookElementSelection)

然后,当您尝试再次使用该变量时,您会得到一个未终止的字符串:

$('hookElementSelection).hide();

应该是:

hookElementSelection.hide();

关于javascript - 如何通过创建div来隐藏JSON数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28920538/

相关文章:

javascript - $http.get 同步 AngularJS

javascript - 弹出窗口不会通过使用模态类进入 Bootstrap

jquery - 使用 jQuery 在悬停时添加元素

php - 在 PHP 中选择一行并将该数据放入表单/文本字段中

javascript - 如何使用代码检查浏览器中的弹出窗口阻止程序是否打开?

javascript - JS从多维数组中获取包含值的数组索引

javascript - DataTables:未捕获类型错误:无法读取未定义的属性 'buttons'

javascript - Ajax 按钮向下滑动并附加带有淡入效果的数据

javascript - Ember.js ember-data 和跨域 ajax 请求

javascript - 单击评论后找不到文件,并且无法识别 savecomment.php 的路径