2017-02-22 81 views
-3

在我们的订购系统中,我有一个根本无法访问的嵌入式功能。方便地存在拼写错误,所以当用户点击某个弹出窗口并出现语法问题时会出现拼写错误。用新功能替换javascript函数

有没有办法让我替换那个文本,或者用一个新的函数替换掉所有相同的代码但是拼写正确的函数?

这是我需要编辑的功能..注意确认说'你选择'而不是'你的选择' 我宁愿更换整个东西,因为我可能想做一些其他的编辑,但现在我' d喜欢修复拼写错误。

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(); 

} 
+2

只是重新定义函数(具有相同的名称和纠正码)在范围更接近您要使用它。 –

+0

为什么你不能访问代码? –

+0

取决于它被定义的位置以及它如何被引用/调用。 –

回答

0

它并不真正身在何处的原始功能是,你如何访问它,只要你只是重新定义函数(具有相同的名称和纠正码)在范围更接近要用它。

下面是一个例子:

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();

+0

终于得到这个工作,并标记为答案斯科特。主要障碍是找到我可以放置它的位置,以便在代码中显示原始位置。 –