簡體   English   中英

如何在javascript中將值從一頁傳遞到另一頁

[英]how to pass values from one page to another page in javascript

嗨,我有一個用javascript創建的表,我需要知道的是如何使用javascript並單擊按鈕將第1或2行中的值傳遞到aspx頁面:這是我的javascript代碼:

newContent += Hesto.Html.StartTR(item.CommonCable, 'lineInfoRow');
            newContent += Hesto.Html.CreateTD('<input type="button" value="Print" id="btnprint" onclick="Redirect()">',null);
            newContent += Hesto.Html.CreateTD(item.CommonCable, null, null);
            newContent += Hesto.Html.CreateTD(item.Wire, null, null);
            newContent += Hesto.Html.CreateTD(item.WireLength * 1000, null, 'centerAlign');
            newContent += Hesto.Html.CreateTD(item.TerminalA, null, (sideFlag == 1 ? 'highlightOneSide' : (sideFlag == 3 ? 'highlightTwoSides' : 'highlightNone')));
            newContent += Hesto.Html.CreateTD(item.SealA, null, (sideFlag == 1 ? 'highlightOneSide' : (sideFlag == 3 ? 'highlightTwoSides' : 'highlightNone')));
            newContent += Hesto.Html.CreateTD(item.TerminalB, null, (sideFlag == 2 ? 'highlightOneSide' : (sideFlag == 3 ? 'highlightTwoSides' : 'highlightNone')));
            newContent += Hesto.Html.CreateTD(item.SealB, null, (sideFlag == 2 ? 'highlightOneSide' : (sideFlag == 3 ? 'highlightTwoSides' : 'highlightNone')));
            newContent = Hesto.Html.EndTR(newContent);
        });

        $('#AlternativeReworkCablesList').html(newContent);
    }

這是我的重定向頁面:

function Redirect() {
    window.open ("http://10.19.13.67/ReworkLabels/Default.aspx","my window");
    return false;
}

您有幾種選擇:您可以將數據保存在cookie中以供以后重用,可以將數據作為一系列GET變量傳遞到下一頁,或者可以使用AJAX加載下一頁,以便保留變量可用。

由於您使用的是ASP,因此可以執行以下操作:

function Redirect() {
    window.open ("http://10.19.13.67/ReworkLabels/Default.aspx?myVariable=" + myVariable,"my window");
    return false;
}

要發送大量數據,您可以嘗試以下操作:

  1. 使用方法post和action創建與您要重定向到的url相等的表單(表單可以隱藏-沒問題)
  2. 以這種形式創建textarea / text字段(不必要)
  3. 將您的數據放在此文本區域
  4. 通過JS提交表單
  5. 在新頁面上接收數據

請注意,javascript將以這種形式轉義數據。 要取消轉義,請使用unescape()函數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM