[英]how to write if and else statement inside single quote?
I have been tried to check an if statement inside single quote but I got an error which is : Uncaught SyntaxError: Unexpected token if
, my code : 我已经尝试在单引号内检查if语句,但是我收到一个错误:
Uncaught SyntaxError: Unexpected token if
,我的代码:
<script>
for($i=0;$i<len;$i++){
text='<div class="col-lg-2 col-md-2 col-sm-2 col-xs-12 pull-right text-left-sm star_div" >'+
'<h5 class="star_h5" >'+
if(1=1){
}
' </h5>'+
'</div>';
}
</script>
my goal I want to check if and else statement inside single quote? 我的目标我想检查单引号内是否和其他声明?
for ($i = 0; $i < len; $i++) {
text = '<div class="col-lg-2 col-md-2 col-sm-2 col-xs-12 pull-right text-left-sm star_div" >' +
'<h5 class="star_h5" >' +
((1 == 1) ? 'ONE' : 'NOT ONE')
+ ' </h5>' + '</div>';
}
OR 要么
for (var $i = 0; $i < 10; $i++) {
text = '<div class="col-lg-2 col-md-2 col-sm-2 col-xs-12 pull-right text-left-sm star_div" >' +
'<h5 class="star_h5" >' +
(function () {
if (1 == 1) {
return 'ONE';
}
return '';
}())
+ ' </h5>' + '</div>';
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.