JavaScript无法正常工作/在IE11上触发-我在脚本中使用onclick = function()-SCRIPT5控制台错误

时间:2018-12-07 10:11:48

标签: javascript internet-explorer onclick internet-explorer-11

我为我的组织的网站创建了一个嵌入。它适用于所有浏览器(包括Edge),但不适用于IE 11。我收到SCTIPT5:访问被拒绝。...

下面是一个片段[我的脚本的宠物。它会在除IE 11之外的所有浏览器上触发。有人了解到什么了吗?

//Variables
var count = 0 //Yes button click count
var q1 = document.getElementById('q1');
var q2 = document.getElementById('q2');
var q3 = document.getElementById('q3');
var q4 = document.getElementById('q4');
var q5 = document.getElementById('q5');
var cloud0 = document.getElementById('cloud0');
var cloud1 = document.getElementById('cloud1');
var cloud2 = document.getElementById('cloud2');
var cloud3 = document.getElementById('cloud3');
var results = document.getElementById('results');
var result0 = document.getElementById('result0');

//Tracking
var dataLayer = dataLayer || [];
var qNum = 1;

//Question 1 Yes and No button. Actions when they are clicked.
yes1.onclick = function() {
  count ++ ;
    q1.style.display = "none";
    q2.style.display = "inline";
        if (count === 1) {
        cloud0.style.display = "none";
        cloud1.style.display = "block";
    }
    sendEvent(qNum,'yes');
    qNum++;
}

no1.onclick = function() {
    q1.style.display = "none";
    q2.style.display = "inline";
    sendEvent(qNum,'no');
    qNum++;
}


//Question 2 Yes and No button. Actions when they are clicked.
yes2.onclick = function() {
  count ++ ;
    q2.style.display = "none";
    q3.style.display = "inline";
        if (count === 1) {
        cloud0.style.display = "none";
        cloud1.style.display = "block";
    } else if (count === 2) {
        cloud1.style.display = "none";
        cloud2.style.display = "block";
    }
    sendEvent(qNum,'yes');
    qNum++;
}

no2.onclick = function() {
    q2.style.display = "none";
    q3.style.display = "inline";
    sendEvent(qNum,'no');
    qNum++;
}

在HTML文件中单击按钮时,将显示下一个问题和新按钮,而上一个按钮将被隐藏。

以下是我的HTML的摘要以帮助您:

<div class="quiz" id="quiz">

  <div role="question" class="q" id="q1">
    <div class="layoutq">
      <p class="qnumber" id="qnumber1">1</p>
      <P class="qtext" id="qtext1">Do you usually go up to or over the limit on your cards or overdraft?</P>
    </div>
    <div class="layoutbutton">
      <button role="button" type="button" class="btn btn-o btn-sm" id="yes1">Yes</button>
      <button role="button" type="button" class="btn btn-o btn-sm" id="no1">No</button>
    </div>
  </div>

  <div role="question" class="q" id="q2">
    <div class="layoutq">
      <P class="qnumber" id="qnumber2">2</P>
      <P class="qtext" id="qtext2">Have you borrowed more money to cover your debt payments?</P>
    </div>
    <div class="layoutbutton">
      <button role="button" type="button" class="btn btn-o btn-sm" id="yes2" class="yesbutton">Yes</button>
      <button role="button" type="button" class="btn btn-o btn-sm" id="no2">No</button>
    </div>
  </div>

  <div role="question" class="q" id="q3">
    <div class="layoutq">
      <P class="qnumber" id="qnumber3">3</P>
      <P class="qtext" id="qtext3">Have you considered or applied for a debt consolidation loan recently?</P>
    </div>
    <div class="layoutbutton">
      <button role="button" type="button" class="btn btn-o btn-sm" id="yes3">Yes</button>
      <button role="button" type="button" class="btn btn-o btn-sm" id="no3">No</button>
    </div>
  </div>

  <div role="question" class="q" id="q4">
    <div class="layoutq">
      <P class="qnumber" id="qnumber4">4</P>
      <P class="qtext" id="qtext4">Are you having issues paying your household bills?</P>
    </div>
    <div class="layoutbutton">
      <button role="button" type="button" class="btn btn-o btn-sm" id="yes4">Yes</button>
      <button role="button" type="button" class="btn btn-o btn-sm" id="no4">No</button>
    </div>
  </div>

  <div role="question" class="q" id="q5">
    <div class="layoutq">
      <P class="qnumber" id="qnumber5">5</P>
      <P class="qtext" id="qtex5">Have you borrowed following job loss, illness or an upheaval in your life?</P>
    </div>
    <div class="layoutbutton">
      <button role="button" type="button" class="btn btn-o btn-sm" id="yes5">Yes</button>
      <button role="button" type="button" class="btn btn-o btn-sm" id="no5">No</button>
    </div>
  </div>

</div>

非常感谢大家

标记

1 个答案:

答案 0 :(得分:0)

我通过在脚本中定义按钮变量来解决此问题。现在一切正常。感谢您的建议。 mplungjan你的建议救了我的培根!

欢呼