一千萬個為什麽

搜索

如何獲得價值

Using C# & Java Script

我有這樣的鏈接

"http://localhost/Server/Vehicle/Vehicle.aspx?appid=5", when i use this link the page is opening... But i want to get this appid value, then pass this appid value to another link

在上面的鏈接appid值是5

例如

Link1 http://localhost/Server/Vehicle/Vehicle.aspx?appid=5

在link2中,值5應顯示為“ http://localhost/Server/Vehicle/car.aspx?appid = 5

試過的代碼

Entry

但在另一個頁面中,鏈接顯示如下

http://localhost/Server/Vehicle/car.aspx?param=document.getElementById('appid').value

如何獲得appid值。我想將此值傳遞給另一個鏈接

需要代碼幫助

最佳答案

按如下方式訪問 Request.QueryString 以檢索 appid 查詢變量的值:

string appid = Request.QueryString["appid"];

Update:

JavaScript代碼段不會在鏈接的 href 屬性中執行(它被識別為普通字符串,不會被解析為JavaScript代碼)。

使用以下鏈接,用戶將成功定向到您想要的URL:

Entry

Side note: the value property works only for HTML tags that have defined an eponymous attribute. One such tag would be the input tag. The div tag instead doesn't have a value attribute defined, and therefore document.getElementById('appid').value would fail; use innerHTML instead in that case.

轉載註明原文: 如何獲得價值