当前位置:网站首页>[es6] 模板字符串内添加if判断或添加三元运算符判断
[es6] 模板字符串内添加if判断或添加三元运算符判断
2022-07-05 15:49:00 【533_】
模板字符串内添加if判断或添加三元运算符判断
es6模板字符串例子:
var html = `<div class="a2"> <p>1</p> <p>2</p> <p>3</p> <p>4</p> </div>`
模板字符串内添加if判断
var html = `<div class="a2"> <p>1</p> <p>2</p> <p>3</p> <p> ${
(function(){
if(XXXXXXXXX){
//条件 return `XXXX`; }else{
return ''; } })() } </p> </div>`
- 不要忘记在function结束以后再加一个(),否则会按照字符串直接解析了
- 如果返回的是一个动态数据记得
return ``
,如果使用return ''
也是会直接解析为字符串
不要忘记在function结束以后再加一个(),否则会按照字符串直接解析了
如果返回的是一个动态数据记得return ``,如果使用return ''也是会直接解析为字符串
// 判断添加类名
var html = `<div class="a2">
<p>1</p>
<p>2</p>
<p>3</p>
<p ${
data[i].aaa ? 'class="hidden"' : ''></p>
</div>`
// 判断状态
var html = `<div class="a2"> <p>1</p> <p>2</p> <p> ${
data[i].status == '0' ? '空闲' : data[i].status == '1' ? '不空闲' : data[i].status == '2' ? '完成' : '没完成'} </p> <p>4</p> </div>`
边栏推荐
- 【学术相关】多位博士毕业去了三四流高校,目前惨不忍睹……
- Modify PyUnit_ Time makes it support the time text of 'xx~xx months'
- vulnhub-FirstBlood
- Cartoon: what is blue-green deployment?
- Five common negotiation strategies of consulting companies and how to safeguard their own interests
- Boost the development of digital economy and consolidate the base of digital talents - the digital talent competition was successfully held in Kunming
- 漫画:什么是分布式事务?
- This article takes you through the addition, deletion, modification and query of JS processing tree structure data
- 超分辨率技术在实时音视频领域的研究与实践
- ES6深入—ES6 Generator 函数
猜你喜欢
PSPNet | 语义分割及场景分析
obj集合转为实体集合
Which keywords will conflict with the abstract keyword
普洛斯数据中心发布DC Brain系统,科技赋能智慧化运营管理
18.[stm32] read the ROM of DS18B20 temperature sensor and realize multi-point temperature measurement
2020-2022两周年创作纪念日
Research and practice of super-resolution technology in the field of real-time audio and video
英特尔第13代Raptor Lake处理器信息曝光:更多核心 更大缓存
Flet教程之 11 Row组件在水平数组中显示其子项的控件 基础入门(教程含源码)
The database of the server is not connected to 200310060 "unknown error" [the service is up, the firewall is off, the port is on, and the netlent port is not connected]
随机推荐
list去重并统计个数
服务器的数据库连不上了2003,10060“Unknown error“【服务已起、防火墙已关、端口已开、netlent 端口不通】
记一次'非常诡异'的云安全组规则问题排查过程
效果编辑器新版上线!3D渲染、加标注、设置动画,这次一个编辑器就够了
Flet教程之 09 NavigationRail 基础入门(教程含源码)
详解SQL中Groupings Sets 语句的功能和底层实现逻辑
19.[STM32]HC_ SR04 ultrasonic ranging_ Timer mode (OLED display)
Exception com alibaba. fastjson. JSONException: not match : - =
Boost the development of digital economy and consolidate the base of digital talents - the digital talent competition was successfully held in Kunming
Coding devsecops helps financial enterprises run out of digital acceleration
HiEngine:可媲美本地的云原生内存数据库引擎
《21天精通TypeScript-3》-安装搭建TypeScript开发环境.md
The visual experience has been comprehensively upgraded, and Howell group and Intel Evo 3.0 have jointly accelerated the reform of the PC industry
List uses stream flow to add according to the number of certain attributes of the element
清晰还原31年前现场,火山引擎超清修复Beyond经典演唱会
Apiccloud cloud debugging solution
Pits encountered in the use of boolean type in development
Cartoon: what is MapReduce?
sql中set标签的使用
obj解析为集合