搜索
javascript - js 二元运算 放在class里报错
阿神
阿神 2017-04-10 16:24:23
[JavaScript讨论组]

二元运算放在class里不正确,
应该怎么写才正确
(item.is_supported != 0)? text-danger : item.support_count;

html+=     '<p id="like_' + item.id + '"  class="col-xs-4" onclick="tones();like(' + item.id + ')"><p style="font-size: 16px;" class="iconfont icon-likefill inline animated ' + (item.is_supported != 0)? text-danger : item.support_count; + '">' + [i] + '</p></p>';
阿神
阿神

闭关修行中......

全部回复(2)
迷茫

分开来写,不容易出错

var pClass='iconfont icon-likefill inline animated ' + (item.is_supported != 0)? 'text-danger':item.support_count;

html+='<p id="like_' + item.id + '"  class="col-xs-4" onclick="tones();like(' + item.id + ')"><p style="font-size: 16px;" class="'+ pClass+'">' + [i] + '</p></p>';
高洛峰

item.support_count 后面那个分号删掉。

分号不是 ? : 运算符的一部分。分号的意思是结束一个语句。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号