用新函数替换javascript函数

时间:2017-02-22 21:11:23

标签: javascript jquery

在我们的订购系统中,有一个我根本无法访问的嵌入式功能。方便地,它有一个拼写错误,因此当用户点击某个弹出窗口并且其中出现语法问题时。

有没有办法让我替换该文本或用一个具有相同代码但拼写正确的新函数替换该函数?

这是我需要编辑的功能..注意确认说“你选择'不是'您的选择' 我更愿意替换整个内容,因为我可能想要进行其他一些编辑但是现在我想修复拼写错误。

 function showProof()
{
    var blnSubmit = false;
    var strHid='';
    var strSave='';

  if (aryTemplateChoices.length == 0) 
  {
    blnSubmit = true;
  }
  else
  {
    for (var i=1; i<=aryTemplateChoices.length; i++)
    {
        strSave = aryTemplateChoices[i-1];
        if (strSave=='')strSave='0';
        if (document.getElementById('hidctrl'+ i))strHid = document.getElementById('hidctrl'+ i).value;
        if (strHid=='')strHid='0';

      if ((strSave != '0') && (strHid != strSave))
      {
        blnSubmit = true;
        break;
      }

    }
  }

  if (blnSubmit)
  {
    if (confirm('Your selection has changed, do you want to save?'))
    {
      document.getElementById('subtype').value = 'proof';
      document.getElementById('prevclick').value = '';
      document.getElementById('frm1').submit();
    }
  }

  canAddToCart();
  //<!--WRITE-->
  getQuantityPrice()
  //<!--/WRITE-->
    loadProof();

} 

1 个答案:

答案 0 :(得分:0)

原始函数的位置以及访问方式并不重要,只要您在距离您想要使用它的位置更近的位置重新定义函数(具有相同的名称和更正的代码) 。

以下是一个例子:

&#13;
&#13;
function foo(){
  console.log("ORIGINAL foo says hello.");
}

function foo(){
  console.log("NEW foo says hello.");
}

// The second declaration is in the same scope as the first, but it comes after the first
// so it overwrites that declaration and the second one is the one that is used.
foo();
&#13;
&#13;
&#13;