2016-11-26 108 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>