Javascript我的If语句出了什么问题?

时间:2017-10-10 15:03:14

标签: javascript html

我在这里有这个Javascript,由于某些原因,只有第一个更新我的div,即使else if几乎相同?否则如果应该触发,任何人都可以帮忙吗?

function giftDD(gift) {
  var dDV = document.getElementById(gift);
  if (garray[gift] > 0) {
    document.getElementById('giftMoney' + gift).remove();
    garray[gift]--;
  }

  var dDD = document.createElement('div');
  if (dDV.value == "Money") {
    alert(dDV.value);
    dDD.setAttribute('id', 'giftMoney' + gift);
    document.getElementById('gifttitle' + gift).innerHTML = "Gift: Money";
    dDD.innerHTML = "<div id='gift#" + gift + "'class='form-group'><div class='form-group'></div><div class='form-group' id='giftno" + gift + "'><div class='form-group'><input type='text' placeholder='£(pounds) e.g. 200' class='f1-gift form-control' name='gift" + gift + "' ng-pattern='/^[0-9]*$/'></input></div><div class='form-group'><input type='text' placeholder='Beneficiary Name...' class='f1-gift form-control' name='benef" + gift + "'></input></div><div class='form-group'><select type='text' class='form-control' name='condition" + gift + "'><div class='form-group'><option value='' selected hidden>Special Conditions...</option><option value='None'>None</option><option value='ReachedAge'>At The Age Of</option><option value='Marriage'>After Marriage</option></div><div class='form-group'></div></div></div>";
    document.getElementById("giftadd" + dDV.id).appendChild(dDD);
    garray[gift]++;
  } else if (dDV.Value === "Shares") {
    alert(dDV.value);
    dDD.setAttribute('id', 'giftShares' + gift);
    document.getElementById('gifttitle' + gift).innerHTML = "Gift: Shares";
    dDD.innerHTML = "<div id='gift#" + gift + "'class='form-group'><div class='form-group'></div><div class='form-group' id='giftno" + gift + "'><div class='form-group'><input type='text' placeholder='Amount of Shares' class='f1-gift form-control' name='gift" + gift + "' ng-pattern='/^[0-9]*$/'></input></div><div class='form-group'><input type='text' placeholder='Beneficiary Name...' class='f1-gift form-control' name='benef" + gift + "'></input></div><div class='form-group'><select type='text' class='form-control' name='condition" + gift + "'><div class='form-group'><option value='' selected hidden>Special Conditions...</option><option value='None'>None</option><option value='ReachedAge'>At The Age Of</option><option value='Marriage'>After Marriage</option></div><div class='form-group'></div></div></div>";
    document.getElementById("giftadd" + dDV.id).appendChild(dDD);
    garray[gift]++;
  }
  alert(dDV.value);
}

1 个答案:

答案 0 :(得分:0)

第二个if语句有错误。

dDV.Value

应该是

dDV.value

JavaScript区分大小写。