我正在尝试在 html 中加载我的模板。但这给我在 div 元素中加载模板内容带来了一些麻烦。它给了我Uncaught TypeError: Object has no method 'appendTo'
temp.html 是 div 所在的文件。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
Remove this if you use the .htaccess -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>HTML</title>
<meta name="description" content="" />
<meta name="author" content="" />
<meta name="viewport" content="width=device-width; initial-scale=1.0" />
<!-- Replace favicon.ico & apple-touch-icon.png in the root of your domain and delete these references -->
<link rel="shortcut icon" href="/favicon.ico" />
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
<script type="text/javascript" src="scripts/jquery-1.4.2.min.js"></script>
<script src="scripts/jquery.tmpl.min.js"></script>
<script>
$.get('template.html', function(templates) {
var template1 = $(templates).filter("tmplFeatures").html();
$("#tmplFeatures").tmpl(template1).appendTo("carouseldata");
});
</script>
</head>
<body>
<div id="carouseldata" style="background-color:#FF0000; width: 100%;height: 100%;z-index: 50">
</div>
</body>
</html>
包含模板的 template.html 文件
<script id ="tmplFeatures" type="text/x-jquery-tmpl">
<div id="mydata" style="overflow-x:hidden;width: 100%;height: 100%">
<ul id="mycarousel" class="jcarousel-skin-tango">
<li><img src="images/image1.jpg" width="400" height="300" alt="" />
<div style="color:#FFFFFF;margin-top: -85px;z-index: 60;background-color: #000000;opacity: 0.5;filter: alpha(opacity=50);width: 400;height:80px">
<img src="images/images.jpg" width="200" height="70" align="middle"/>
<img src="images/divider.png" width="2" height="40" align="middle"/>
<img src="images/cbs.png" width="100" height="70" align="middle"/>
<img src="images/lock.png" align="middle" />
</div>
</li>
<li><img src="images/image2.jpg" width="400" height="300" alt="" />
<div style="color:#FFFFFF;margin-top: -85px;z-index: 60;background-color: #000000;opacity: 0.5;filter: alpha(opacity=50);width: 400;height:80px">
<img src="images/images.jpg" width="200" height="70" align="middle"/>
<img src="images/divider.png" width="2" height="40" align="middle"/>
<img src="images/thumb-comcast.gif" width="100" height="70" align="middle"/>
</div>
</li>
<li><img id="image3" src="images/image3.jpg" width="400" height="300" alt="" />
<div style="color:#FFFFFF;margin-top: -85px;z-index: 60;background-color: #000000;opacity: 0.5;filter: alpha(opacity=50);width: 400;height:80px">
<img src="images/images.jpg" width="200" height="70" align="middle"/>
<img src="images/divider.png" width="2" height="40" align="middle"/>
<img src="images/cbs.png" width="100" height="70" align="middle"/>
</div>
</li>
<li><img src="images/image4.jpg" width="400" height="300" alt="" />
<div style="color:#FFFFFF;margin-top: -85px;z-index: 60;background-color: #000000;opacity: 0.5;filter: alpha(opacity=50);width: 400;height:80px">
<img src="images/images.jpg" width="200" height="70" align="middle"/>
<img src="images/divider.png" width="2" height="40" align="middle"/>
<img src="images/cbs.png" width="100" height="70" align="middle"/>
</div>
</li>
<li><img src="images/image5.jpg" width="400" height="300" alt="" />
<div style="color:#FFFFFF;margin-top: -85px;z-index: 60;background-color: #000000;opacity: 0.5;filter: alpha(opacity=50);width: 400;height:80px">
<img src="images/images.jpg" width="200" height="70" align="middle"/>
<img src="images/divider.png" width="2" height="40" align="middle"/>
<img src="images/cbs.png" width="100" height="70" align="middle"/>
</div>
</li>
<li><img src="images/image6.jpg" width="400" height="300" alt="" />
<div style="color:#FFFFFF;margin-top: -85px;z-index: 60;background-color: #000000;opacity: 0.5;filter: alpha(opacity=50);width: 400;height:80px">
<img src="images/images.jpg" width="200" height="70" align="middle"/>
<img src="images/divider.png" width="2" height="40" align="middle"/>
<img src="images/cbs.png" width="100" height="70" align="middle"/>
</div>
</li>
<li><img src="images/image7.jpg" width="400" height="300" alt="" />
<div style="color:#FFFFFF;margin-top: -85px;z-index: 60;background-color: #000000;opacity: 0.5;filter: alpha(opacity=50);width: 400;height:80px">
<img src="images/images.jpg" width="200" height="70" align="middle"/>
<img src="images/divider.png" width="2" height="40" align="middle"/>
<img src="images/cbs.png" width="100" height="70" align="middle"/>
</div>
</li>
<li><img src="images/image8.jpg" width="400" height="300" alt="" />
<div style="color:#FFFFFF;margin-top: -85px;z-index: 60;background-color: #000000;opacity: 0.5;filter: alpha(opacity=50);width: 400;height:80px">
<img src="images/images.jpg" width="200" height="70" align="middle"/>
<img src="images/divider.png" width="2" height="40" align="middle"/>
<img src="images/cbs.png" width="100" height="70" align="middle"/>
</div>
</li>
<li><img src="images/image9.jpg" width="400" height="300" alt="" />
<div style="color:#FFFFFF;margin-top: -85px;z-index: 60;background-color: #000000;opacity: 0.5;filter: alpha(opacity=50);width: 400;height:80px">
<img src="images/images.jpg" width="200" height="70" align="middle"/>
<img src="images/divider.png" width="2" height="40" align="middle"/>
<img src="images/cbs.png" width="100" height="70" align="middle"/>
</div>
</li>
<li><img src="images/image10.jpg" width="400" height="300" alt="" />
<div style="color:#FFFFFF;margin-top: -85px;z-index: 60;background-color: #000000;opacity: 0.5;filter: alpha(opacity=50);width: 400;height:80px">
<img src="images/images.jpg" width="200" height="70" align="middle"/>
<img src="images/divider.png" width="2" height="40" align="middle"/>
<img src="images/cbs.png" width="100" height="70" align="middle"/>
</div>
</li>
</ul>
</div>
</script>