gpt4 book ai didi

javascript - 未捕获的类型错误 : Cannot read property 'replace' of undefined -underscore

转载 作者:行者123 更新时间:2023-12-02 15:12:29 25 4
gpt4 key购买 nike

我是 underscore.js 和 jquery 的初学者,当我创建如下所示的简单模板时:

<html>
<body>

<script src="E:/its me/softies/blackhole.com/underscore.js" type="text/javascript"></script>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>


<script type ="text/javascript" id="tem">
var head = "hii";
//var head2 = "hello";
var templ = _.template($('#temp').html()) ;
$('#tagent').append(templ,{head:head});
</script>

<script type="text/template" id="temp">
<h1><%=head></h1>
<h2><%=head2></h2>
</script>

<div class="tangent"></div>
</body>

它显示一个错误:未捕获类型错误:无法读取未定义的属性“替换” 我使用括号编辑器。如果有人能告诉我,我将非常感激1)这是什么错误?2)我哪里出错了? 。提前非常感谢。

最佳答案

您的脚本在模板可用之前执行,您需要在 document.ready 上执行它或将脚本 block 移至模板定义下方。

关于javascript - 未捕获的类型错误 : Cannot read property 'replace' of undefined -underscore,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34714067/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com