2017-04-21 82 views
0

我有這個代碼,我似乎無法正常工作,我希望我發佈這個正確的,我想有用戶文本輸入取代原始的href鏈接10分鐘,然後點擊這個時間段的其他訪問者,然後返回到原始的href。每10分鐘一遍又一遍地重複。任何和所有的幫助將不勝感激。動態地改變herf鏈接與用戶文本輸入

<script type="text/javascript"> 
 
function changeURLOfAnchorWithID(anchor_id,new_href) 
 
\t { 
 
\t document.getElementById("anchor").href = new_href; 
 
\t } 
 

 
function formOnSubmit(formElm) 
 
\t { 
 
\t changeURLOfAnchorWithID("anchor",formElm.new_url.value+""); 
 
\t return false; 
 
\t } 
 
</script> 
 
</head> 
 
<body> 
 
<a id="anchor" href="https://www.whatever.com/"> <!--Keeps new url active for 10 minutes after user leaves site and other visitors are able to click there submitted link instead, then resets to default setting after 10 minutes--> 
 
<img border="0" src="https://www.whatever.com" width="468" height="60"></a> 
 

 
<form onsubmit="return formOnSubmit(this)"> 
 
<input type="text" name="new_url" value="" size="36" /><br /> <!--value added to the end of the static address in the anchor tag --> 
 
<input type="submit" value="change href" /> 
 
</form>

行,所以這是我想出,PHP做工不錯並更新一個單獨的頁面上的信息,我想有一個在輸入的信息該文本框會替換PHP頁面上的HREF鏈接的末尾,並保持最少10分鐘,直到其他人使用輸入更新PHP。我已經決定,在10分鐘後,鏈接不需要恢復到原始鏈接。

HTML

<form method="post" action="phptest.php"> 
<textarea name="Box" cols="20" rows="1"></textarea><br> 
<input type="submit" value="Submit" /> 
</form> 

PHP

<?php echo $_POST["Box"] ?> 

回答

0

您需要進行此更改對所有用戶可見。你不能通過只使用JavaScript來做到這一點。 JavaScript是一種客戶端腳本語言。它在客戶機上運行。

要做到這一點,您必須使用任何服務器端腳本語言,如PHP,ASP或JSP。在提交時,鏈接必須轉到服務器,並且應該存儲在數據庫中。當新用戶請求該頁面時,應根據存儲在數據庫中的鏈接生成頁面。 要在10分鐘後自動更改鏈接,請使用cron作業。我相信這有助於。