如果声明没有执行,如果一个是假的Javascript

时间:2018-03-20 11:25:44

标签: javascript php

我有一堆if语句,如果其中任何一个是真的,就会创建一个卡并以HTML格式显示,问题是当top if语句为false时,其余语句将不会被执行。

      if (pr) {
        createViewCard('Purchase Requisition', 'veiwpr');
      }

      if (pc) {
        createViewCard('Petty Cash', 'veiwpc');
      }

      if (cpr) {
        createViewCard('Cheque/Payment Requisition', 'veiwcpr');
      }

      if (ba) {
        createViewCard('Business Advance Form', 'veiwba');
      }

      if (cqc) {
        createViewCard('Comparison Quotation Chart', 'veiwcqc');
      }

if值是从PHP获得的,如果表中的值存在,我将相应的Javascript变量设置为true:

$cr_SQL = "SELECT * FROM created_requests WHERE request_id='$rID'";
$cr_results = mysqli_query($dbcon, $cr_SQL);

while ($row = mysqli_fetch_array($cr_results)) {

  if ($row['name'] == "pr_created") {
    echo "<script>";
    echo "var pr = true;";
    echo "</script>";

    echo $row['name'];
  }

  if ($row['name'] == "ba_created") {
    echo "<script>";
    echo "var ba = true;";
    echo "</script>";

    echo $row['name'];
  }

  if ($row['name'] == "cpr_created") {
    echo "<script>";
    echo "var cpr = true;";
    echo "</script>";

    echo $row['name'];
  }

  if ($row['name'] == "cqc_created") {
    echo "<script>";
    echo "var cqc = true;";
    echo "</script>";

    echo $row['name'];
  }

  if ($row['name'] == "pc_created") {
    echo "<script>";
    echo "var pc = true;";
    echo "</script>";

    echo $row['name'];
  }
}

1 个答案:

答案 0 :(得分:0)

像这样做修好它。

document.getElementById('scene').innerHTML = message