如何用代码注入替换JS中的所有类实例?

时间:2015-06-10 21:06:41

标签: javascript squarespace

我想说我想替换表单上的所有选项实例(同意/不同意/中立)。我似乎不会在每个实例的第一个实例中发生这种情况,而不是整个页面。

实施例

这是我到目前为止所处的位置:

<script>
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
} 
addLoadEvent(function() {

//Songwriting
  sqsRadio = document.getElementsByClassName("option")[0].innerHTML;
  myRadio = sqsRadio.replace("Strongly Disagree", "Fortement Désaccord");
  document.getElementsByClassName("option")[0].innerHTML = myRadio;

  sqsRadio = document.getElementsByClassName("option")[1].innerHTML;
  myRadio = sqsRadio.replace("Disagree", "Désaccord");
  document.getElementsByClassName("option")[1].innerHTML = myRadio;

  sqsRadio = document.getElementsByClassName("option")[2].innerHTML;
  myRadio = sqsRadio.replace("Neutral", "Neutre");
  document.getElementsByClassName("option")[2].innerHTML = myRadio;

  sqsRadio = document.getElementsByClassName("option")[3].innerHTML;
  myRadio = sqsRadio.replace("Agree", "d'Accord");
  document.getElementsByClassName("option")[3].innerHTML = myRadio;

  sqsRadio = document.getElementsByClassName("option")[4].innerHTML;
  myRadio = sqsRadio.replace("Strongly Agree", "Fortement d'Accord");
  document.getElementsByClassName("option")[4].innerHTML = myRadio;

});
</script>

0 个答案:

没有答案