簡體   English   中英

如何使搜索框鏈接到我頁面上的網站?

[英]How do I make a search box link to a site on my page?

我正在尋找一個簡單的搜索框,該鏈接將鏈接到我網站上的特定目標,並添加“?id = ...”,其中...就是他們在搜索框中輸入的內容。 例如,如果他們要在搜索框中鍵入7654143,則會將其鏈接到... / player?id = 7654143

我相信我知道如何做它的html部分,但是當涉及到javascript時我迷路了,這是我認為我需要它才能起作用的...

除此之外,如果輸入的內容與要求的准則不符(數字必須以7654開頭,並且長度必須完全為15個字符),則搜索框的背景顏色將以紅色閃爍1秒並過渡

 <!DOCTYPE html> <html> <head> <title>Stats page</title> <link href="css/style.css" type="text/css" rel="stylesheet"> <link href="https://fonts.googleapis.com/css?family=Ubuntu:400,500" rel="stylesheet"> </head> <body class=body> <div class="header"> <a href=#>Leaderboards</a> <a href=#>Server stats</a> <a href=# class=active>Search</a> </div> <h1 class=title>Roleplay<span>Stats</span></h1> <div class=search> <input type="text" placeholder="Who are you looking for?"> </div> </body> </html> 

我將專注於此問題的后端部分,其他人可能會參與驗證過程。 對於表單中的“ id =”部分,我將親自使用PHP。 確保您的輸入格式正確,並使用GET方法確保該值輸入URL中。 (假設您的目標頁面是player.php,如果使用此方法,則必須為.php)

在表單頁面上(輸入中的名稱是將放在url中的名稱:player.php?name-of-input = ...):

<form method="get" action="player.php">
    <input type="text" name="id" placeholder="Who are you looking for?">
</form>

在“播放器”頁面上,您必須隔離url中的值,然后獲取與此值相對應的適當播放器,這在PHP派上用場。

在播放器頁面上,應將php部分放在代碼的頂部:

<?php 
   $player = $_GET['id'];
   //The "id" inside the brackets is actually the name of the input in your form
?>

使用此代碼,用戶將輸入ID,該ID將進入URL。 然后,假設播放器頁面是player.php,它將具有一個類似於player.php?id = 7654的網址... php代碼將獲取ID,然后您可以執行將輸出適當代碼的代碼播放器。

暫無
暫無

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

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