如何在javascript中写条件?

时间:2017-04-21 11:06:53

标签: javascript

PHP IF条件:

-> <?php if($pet['pet_type'] == 'Lost'){echo $pet['pet_name'];}else{echo 'Please Help Me';}?>

JS IF:

<h3 class="title" style="word-break: break-all;">'+if(res[i].pet_type === 2){res[i].pet_name}else{+'Please help me'+}+'</h3>

请帮助我哪里出错了。我怎样才能解决这个错误?

1 个答案:

答案 0 :(得分:1)

您需要concatenate正确

&#13;
&#13;
var concat = '';
concat = '<h3 class="title" style="word-break: break-all;">';

//if(res[i].pet_type === 2){
if(2 === 2) {

  //value = res[i].pet_name;
  value  = 'sssss';
}
else {
  value = 'Please help me'; 
}

concat+= value+'</h3>';
console.log(concat);
&#13;
&#13;
&#13;