Home  >  Q&A  >  body text

if后面的括号里可以直接写变量或者写true吗 求大神指点 若是写这两者 有什么结果?

<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" 
content="text.html;charset=utf-8">
<title></title>
 <script>
 var addf=confirm("您好 想要进入该网站吗");
 if(true){
   document.write("欢迎访问本网站 很高兴为你服务");
   }
 else
 {
   alert("谢谢 忍痛拒绝");
 }
 </script>


checkcheck2859 days ago1265

reply all(2)I'll reply

  • 数据分析师

    数据分析师2017-09-30 23:35:30

    Can I write variables directly or write true in the brackets after if? Please give me some advice. What will be the result if I write these two? -PHP Chinese website Q&A - Can I write variables directly or write true in the brackets after if? Please give me some advice. What will be the consequences if I write these two? -PHP Chinese website Q&A

    Please watch and learn.

    reply
    0
  • 迷茫

    迷茫2016-12-22 13:28:19

    因为if后面的判断语句就是要判断执行if还是else后面的语句,如果你直接写if(true)的话,if后面永远是true,也就是说无论前面如何改变,都永远执行if里面的语句,不会执行else里面的语句。

    reply
    0
  • Cancelreply