有了art-template,如有神助



<div class="form-group col-lg-12">
<label class="control-label col-lg-3 text-right">类型:</label>
<div style="margin-top:6px">
<input type="radio" name="type" value="1" checked /><label>全场券</label>
<input type="radio" name="type" value="2" /><label>单类券</label>
<input type="radio" name="type" value="3" /><label>单品券</label>
</div>
</div>
增加点击事件
// 点击事件
$("[name=type]:radio").click(function(){
let type = $(this).val();
let html = template('type-tpl', {data:{type:type}});
$('#type-cont').html(html);
});
留一个容器
<!-- 类型容器 -->
<div id="type-cont">
</div>
模板
<script id="type-tpl" type="text/template">
{{ if data.type == 1 }}
{{ else if data.type == 2}}
<div class="form-group col-lg-12">
<label class="control-label col-lg-3 text-right"><span class="control-label required-mark">*</span>选择单类:</label>
<span class="input-group input-group-option">
<select name="type_id" id="type_id" class="form-control" style="position: relative; left:-4px;z-index: 1;border-radius:3px;" aria-describedby="object">
<option value="0">--请选择--</option>
<volist name="type_id_name" id="vo">
<option value="{$vo.id}" <?php if($result['type_id'] == $vo['id']){echo "selected";} ?> >{$vo.name}</option>
</volist>
</select>
</span>
</div>
{{ else if data.type == 3}}
<div class="form-group col-lg-12">
<label class="control-label col-lg-3 text-right"><span class="control-label required-mark">*</span>选择单品:</label>
<span class="input-group input-group-option">
<select name="pid" id="pid" class="form-control" style="position: relative; left:-4px;z-index: 1;border-radius:3px;" aria-describedby="object">
<option value="0">--请选择--</option>
<volist name="product_id_name" id="vo">
<option value="{$vo.id}" <?php if($result['pid'] == $vo['id']){echo "selected";} ?> >{$vo.name}【ID-{$vo.id}】</option>
</volist>
</select>
</span>
</div>
<div id="sku-cont"></div>
{{ /if }}
</script>
<script id="sku-tpl" type="text/html">
<div class="form-group col-lg-12">
<label class="control-label col-lg-3 text-right"><span class="control-label required-mark"></span>适用规格:</label>
<span class="input-group input-group-option">
<select name="sku_id" id="sku_id" class="form-control" style="position: relative; left:-4px;z-index: 1;border-radius:3px;" aria-describedby="object">
<option value="0">全部</option>
{{ each data }}
<option value="{{ $value.id }}">{{ $value.name }}</option>
{{ /each }}
</select>
</span>
</div>
</script>
模板中可以直接使用php模板,也可以用art语法。
选择商品,添加事件
// 选择商品事件
$(document).on('change','#pid',function(){
let pid = parseInt($(this).val());
if (pid > 0) {
// 异步获取商品规格
$.ajax({
type: 'POST',
url: 'ajax_get_sku',
data: {pid: pid},
dataType: 'json',
success: function (data) {
if (data.errno == 0) {
let html = template('sku-tpl', {data:data.data});
$('#sku-cont').html(html);
} else {
layer.msg(data.errdesc, {icon: 5});
return false;
}
}
});
} else {
$('#sku-cont').html('');
}
});
jQ结合模板,可以实现很多灵活的效果!!!非常的好用!!!直接jQ就没那么便利了!!!
有了art-template,如有神助的更多相关文章
- art template前端模板引擎
偶然看到后台有一段代码 采用的是art template的模板引擎 地址为 http://aui.github.io/artTemplate/ 这段代码很简洁 var html = template( ...
- art.template 循环里面分组。
后台提供给我们一个数组,我们要用模版实现上面的格式输出怎么版呢? 下面就是解决方案: <h2>循环4个一组</h2> <script type="text/ht ...
- 利用art.template模仿VUE 一次渲染多个模版
TypeScript代码 import template = require('art-template/lib/template-web'); interface TemplateBindConfi ...
- 利用art.template模仿VUE
首先先看一下Typescript代码: import template = require('art-template/lib/template-web'); interface TemplateBi ...
- js 模板引擎 -Art Template
一个例子涵盖所有: <!doctype html> <html> <head> <meta charset="UTF-8"> < ...
- awesome python 中文版 相见恨晚!
awesome python 中文版 相见恨晚! https://www.zhihu.com/question/24590883 这篇知乎厉害了!一定要学习! 作者:知乎用户链接:https:// ...
- python模块大全
python模块大全2018年01月25日 13:38:55 mcj1314bb 阅读数:3049 pymatgen multidict yarl regex gvar tifffile jupyte ...
- C++ Primer学习笔记(一)
始终对C++念念不忘,看过 一个32岁入门的70后程序员给我的启示 之后,心情激荡,更是一发不可收拾. 认真地说,我不是一个执着的人,见异思迁,好读书而不求甚解,兼之情绪化(~~ 某些方面),于是怒 ...
- Python3.x:第三方库简介
Python3.x:第三方库简介 环境管理 管理 Python 版本和环境的工具 p – 非常简单的交互式 python 版本管理工具. pyenv – 简单的 Python 版本管理工具. Vex ...
随机推荐
- 删去k个数字后的最小值
public static String removeKDigits(String num,int k) { //新整数的最终长度=原长度 - k int newLength=num.length() ...
- Eloquent JavaScript #08# Bugs and Errors
索引 Notes strict mode js类型 js测试 Debugging Exceptions finally 异常分支 Exercise Retry The locked box Notes ...
- vi/vim 命令速查手册
vi 的基本概念 基本上vi可分为三种操作状态,分别是命令模式(Command mode).插入模式(Insert mode)和底线命令模式(Last line mode),各模式的功能区分如下: 1 ...
- ElasticSearch vs Solr多维度分析对比
福利 => 每天都推送 欢迎大家,关注微信扫码并加入我的4个微信公众号: 大数据躺过的坑 Java从入门到架构师 人工智能躺过的坑 Java全栈大联盟 ...
- Centos部署flask项目
必备: Python2.7(ok) MySQL(ok) git supervisor virtualenv Gunicorn 阿里云服务器(最便宜的就好) 域名(国内万网,国外goDaddy) 我的P ...
- 运行android模拟器,emulator: ERROR: x86 emulation currently requires hardware acceleration!
运行android模拟器,emulator: ERROR: x86 emulation currently requires hardware acceleration! 问题: 运行android模 ...
- css3-动画(animation)
css3-动画(animation): 具有以下属性: 1.animation-name 自定义动画名称 2.animation-duration 动画指定需要多少秒或毫秒完成,默认值是0; 3.an ...
- CentOS6.8下安装Redis
1.由于Redis是使用C语言开发的,安装时需要对Redis的源码进行编译,编译依赖gcc环境,如果没有gcc,需要先安装gcc: yum install gcc-c++ 2.安装完成后,进入Redi ...
- Selenium Webdriver wait for JavaScript JQuery and Angular
Hi all, during the last two weeks I was dealing with the best solution to wait for both JQuery, Angu ...
- JSON(JavaScript Object Notation, JS 对象标记)
JSON(JavaScript Object Notation, JS 对象标记) 是一种轻量级的数据交换格式.它基于 ECMAScript (w3c制定的js规范)的一个子集,采用完全独立于编程语言 ...