JavaScript type="text/template"相当于定义一个模板,如果没有使用html()方法的话,是显示不出来的,我们直接看例子(我是在tp框架的里面写的)

<div class="container"> <div class="waterfall"> </div> </div>

定义一个模板:

 <!-- 一个模板  -->
<script id="waterfall-template" type="text/template">
<?php foreach ($list as $key => $value) { ?>
<ul class="list-group">
<li class="list-group-item">
<a href="javascript:;"><img src="<?php echo $value['banner_image']; ?>" /></a>
</li>
<li class="list-group-item">
<a href="{:U('Admin/Banner/banner_detail',array('banner'=>$value['banner_id']))}"><button type="button" class="btn btn-default btn-xs" title="thumb up"><span class="fa fa-pencil"></span></button></a>
<a href="#myModal" class="del_btn" role="button" data-toggle="modal" data-banner="<?php echo $value['banner_id']; ?>"><button type="button" class="btn btn-default btn-xs"><i class="fa fa-trash-o"></i></button></a>
<span style="float: right;"><?php echo $value['banner_type'] == 1?'首页':'';?></span>
</li>
</ul>
<?php } ?>
</script>

使用:

 <script>
$('.waterfall').data('bootstrap-waterfall-template', $('#waterfall-template').html()).waterfall();
var del_data = null;
$(".waterfall").on('click','.del_btn',function(){
del_data = $(this).attr('data-banner');
});
$('.btn-danger').click(function(){
if (del_data) {
window.location.href = '{:U("Admin/Banner/banner_del")}?banner_id=' + del_data;
}
});
</script>

参考其他人的资料:http://www.cnblogs.com/olivianate/p/5364850.html

我这里的案例是写一个流水布局的。waterfall()

JavaScript type="text/template"的用法的更多相关文章

  1. 前端模板<script type="text/template" id="tmpl">

    前端模板, 比连接字符串好用多了, 还可以使用循环\判断等语句, 减少工作量 <script type="text/template" id="member-tmp ...

  2. 关于MVC模板渲染的一点小事type="text/template"

    先上一个demo,简单粗暴,请自便 <!DOCTYPE html> <html> <head lang="en"> <meta chars ...

  3. <script type="text/template">是干什么的,为什么要把html写在js中? 这是什么编程语言风格,都能这样用吗?

    这一段存放了一个模板.在js里面,经常需要使用js往页面中插入html内容.比如这样: var number = 123; $('#d').append('<div class="t& ...

  4. 关于 <script type='text/template' > 的妙用 / 使用jquery获取iframe加载完成事件

    https://www.cnblogs.com/ddqyc/p/6200539.html <!DOCTYPE html> <html> <head> <met ...

  5. Js script type="text/template"的使用简单说明

    <script type="text/template" id="treeTableTpl"> <tr id="{{row.id}} ...

  6. JS的type类型为 text/template

    JS标签中有时候会看见<script type="text/tmplate" >,大概就是一个放置模板的地方,而这些东西并不显示在页面 在js里面,经常需要使用js往页 ...

  7. script "text/template"

    <script type="text/template" id="orgItem"> <div class="{orgClass}& ...

  8. <script type="text/x-template"> 模板

    获取动态的js模板可以用art-template插件 <script type="text/template"> 给<script>设置type=" ...

  9. document.write('<script type=\"text/javascript\"><\/script>')

    document.write('<script type=\"text/javascript\"><\/script>')

随机推荐

  1. 思考设计SQL优化方案

    一.优化的哲学 注:优化有风险,涉足需谨慎 1.优化可能带来的问题? 优化不总是对一个单纯的环境进行,还很可能是一个复杂的已投产的系统: 优化手段本来就有很大的风险,只不过你没能力意识到和预见到: 任 ...

  2. 关于 IDEA 启动 springboot 项目异常 - Disconnected from the target VM, address: '127.0.0.1:59770', transport: 'socket'

    关于 IDEA 启动 springboot 项目异常 - Disconnected from the target VM, address: '127.0.0.1:59770', transport: ...

  3. 【纯净镜像】原版Windows7集成USB3.0+NVME补丁+UEFI引导旗舰版下载

    系统简述: 1. 基于MSDN原版Windows7 Ultimate With SP1系统制作,无任何插件和垃圾软件. 2. 系统集成IE11浏览器,装完系统后默认浏览器就是IE11. 3.系统注入了 ...

  4. python 控制台输出美化

    #格式: 设置颜色开始 :\033[显示方式;前景色;背景色m #说明: 前景色 背景色 颜色 --------------------------------------- 黑色 红色 绿色 黃色 ...

  5. Light of future-测试总结

    目录 1.描述项目的测试工作安排 2.测试工具选择和运用 3.测试用例文档pdf的github链接地址 4.测试体会 5.项目测试评述 发布界面 后台CRUD 归属班级 →2019秋福大软件工程实践Z ...

  6. CSS制作小旗子与小箭头

    CSS制作小旗子与小箭头 效果图如下: 小旗子效果图 小箭头效果图 小旗子效果 以下是具体实现代码: <div class="container"> <div c ...

  7. python开发基于SMTP协议的邮件代发服务

    写在这篇文章前照例给大家灌输点名词解释,理论知识,当然已经很熟悉的同学可以往下翻直接看干货 1. 什么是SMTP SMTP即简单传输协议(Simple Mail Transfer Protocol), ...

  8. python的字符串、列表、字典和函数

    一.字符串 在python中字符串无需通过像php中的explode或者javascript中的split进行分解即可完成切片,可以直接通过下标获取字符串中的每一个字符,下标从0开始,如果从厚望签署, ...

  9. Python设计模式(8)-抽象工厂

    # coding=utf-8 这种方式反倒把事情做复杂了 可取之处在于有了更高层次的抽象 class IEmployee: def insert_employee(self): pass class ...

  10. AD颗粒化密码规则策略

    我们在第一次设定密码规则的时候,通常会在根节点或者默认组策略中设置 如果,我们在后期运维过程中,有一些特殊用户需要设置额外的密码策略,我们要如何操作呢? 可能,有些同学会在这些特殊用户对应的OU下在创 ...