为了隐藏 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/