2013-03-19 149 views
1

我有一個web應用程序。我正在使用鏈接...:8080/EPQ /訪問Web應用程序。 Web應用程序只有一個HTML文件。我在HTML中有以下代碼。Web應用程序HTML參數傳遞

<input type="hidden" name="id" id ="id" > 

我想通過URL ...:8080/EPQ /傳遞此id的值。讓我知道如何做到這一點。

+0

URL的形式爲http:// someip:8080/EPQ/ – Ramesh 2013-03-19 03:13:10

+1

如果HTML源代碼,是你的,那麼你可以考慮使用PHP來傳遞值。 url.com?變量=值 – lukeocom 2013-03-19 03:56:51

+0

@lukeocom我試着查詢字符串像someip:8080/EPQ /?id = 1000。價值沒有得到通過。 HTML是我的。我可以修改它。 – Ramesh 2013-03-19 04:20:20

回答

1

如果您將文件更改爲具有.php擴展名而不是.html,那麼您可以使用腳本檢查是否已將值添加到url。你的服務器必須安裝php才能工作。

一個例子在你的php文件中看起來像這樣。

<?php 
    //check if var is in URL and store it in $yourVar otherwise store the string 'blank text' 
    if ($_GET) { 
     $yourVar = $_GET['hidden-val']; 
    } else {$yourVar = 'blank text'; 
    } 
?> 

您的網址會是這個樣子

http://www.yourdomain.com/yourfile.php?hidden-val=somevalue

,或者如果該文件是index.php文件,你可以使用

http://www.yourdomain.com/?hidden-val=somevalue

另一種解決方案是使用javascript/jquery的方法,這將看起來像..

$(document).ready(function() { 
    var yourVar = window.location.search.substring(1); 
    alert('you passed in ' + yourVar); 
} 

這個線程可能會有所幫助也.. How to get the value from the GET parameters?

+0

非常感謝。上面的JavaScript代碼正在工作。 – Ramesh 2013-03-19 06:38:48

相關問題