我希望制作一个简单的搜索框,链接到我网站上的特定目的地,并添加“?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>
答案 0 :(得分:0)
我将专注于此问题的后端部分,其他人可能会参与验证过程。对于表单中的“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>
在“播放器”页面上,您必须隔离网址中的值,然后获取与此值对应的相应播放器,这就是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然后你可以执行输出相应的代码播放器。