Javascript jQuery模板不工作(jQuery 3.4.1)
我不确定我的代码出了什么问题。当我在Firefox中打开它时,它什么都不做。 然而,将其复制到fsfiddle中是可行的 我是否缺少jQuery模板的JavaScript文件,但我认为这是在1.5中添加到jQuery的 为什么Javascript jQuery模板不工作(jQuery 3.4.1),javascript,jquery,html,jquery-templates,Javascript,Jquery,Html,Jquery Templates,我不确定我的代码出了什么问题。当我在Firefox中打开它时,它什么都不做。 然而,将其复制到fsfiddle中是可行的 我是否缺少jQuery模板的JavaScript文件,但我认为这是在1.5中添加到jQuery的 为什么 考试随机发生器 ${sQuestionText} //使用模板呈现书籍 $(“#问题模板”).tmpl(oQuestions).appendTo(“#主容器”); 您可以共享main.js文件吗?问题来自哪里?我现在自己解决了。问题是我试图将js数组与jquery模板
考试随机发生器
${sQuestionText}
//使用模板呈现书籍
$(“#问题模板”).tmpl(oQuestions).appendTo(“#主容器”);
您可以共享main.js文件吗?问题来自哪里?我现在自己解决了。问题是我试图将js数组与jquery模板一起使用。我认为它在jsfiddle中工作的原因是,jsfiddle不小心为我转换了它,这样它就可以运行我在textbox中键入的代码。var oQuestions2=$.makeArray(oQuestions);我一加上这个就行了
<!DOCTYPE html>
<html>
<head>
<script src="scripts/jquery-3.4.1.js"></script>
<script src="scripts/main.js"></script>
<meta charset="UTF-8">
<title>Exam Random Generator</title>
</head>
<body>
<div id ="mainContainer"> </div>
<script id="questionTemplate" type="text/x-jQuery-tmpl">
<div class="questionContainer">
<p class="question">${sQuestionText}</p>
</div>
<br/>
</script>
<script type="text/javascript">
// Render the books using the template
$("#questionTemplate").tmpl(oQuestions).appendTo("#mainContainer");
</script>
</body>
</html>