2017-02-22 35 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

終於得到這個工作,並標記爲答案斯科特。主要障礙是找到我可以放置它的位置,以便在代碼中顯示原始位置。 –