2016-11-26 157 views
1

我想要的值傳遞從一個網頁到另一個的選擇陣列的如何通過價值選擇選項

價值要通過單擊accSummary時(直接到所需的頁面),這將調用一個函數:

document.getElementById("1").innerHTML = '<a href="acc.html" onclick="getSum[0]">'+accSummary[0].accNo +'</a>'; 
document.getElementById("2").innerHTML = '<a href="acc.html" onclick="getSum[2]">'+accSummary[0].accNo +'</a>'; 

function invoked: (i try to store the value in localStorage) 

getSum(no){ 
    localStorage.setItem("accNo",accDetail[no]); 
} 

我寫這個腳本來獲取值

<script>window.onload = function() { 
     document.getElementById("demo").innerHTML = 
     localStorage.accDetail[no];var createTrans=getTransactions(); 
</script> 
但是

,事實證明,無(localStorage.accDetail [無])是不確定的。

什麼問題

+0

數據爲什麼有方括號中的onclick ** = 'getSum(0)' ** – Dherya

+0

限定作爲函數'function getSum(no)' – prasanth

回答

1

嘗試這樣

1.功能無法定義function getSum(no)

2.更改getSum(0)而不是getSum[0]

3.Already必須聲明本地存儲value.So檢索這樣localStorage.getItem("accNo");

document.getElementById("1").innerHTML = '<a href="acc.html" onclick="getSum(0)">'+accSummary[0].accNo +'</a>'; 
document.getElementById("2").innerHTML = '<a href="acc.html" onclick="getSum(2)">'+accSummary[0].accNo +'</a>'; 



    function getSum(no){ //its a function 
     localStorage.setItem("accNo",accDetail[no]); //assign the value to local 
    } 

     <script> 
      window.onload = function() { 
       document.getElementById("demo").innerHTML =localStorage.getItem("accNo"); //retrieve the data like this 
       var createTrans=getTransactions(); 
     </script>