我想将一个页面的值传递给另一个选项
当点击 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>
然而,事实证明 no (localStorage.accDetail[no]) 是未定义的。
问题是什么
最佳答案
像这样尝试
1.function 没有定义function getSum(no)
。
2.更改 getSum(0)
而不是 getSum[0]
。
3.你已经声明了本地存储值。所以像这样检索数据 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>
关于javascript - 如何传递值以选择选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40815540/