【问题标题】:Html-Search box that links to websites through key wordsHtml-通过关键词链接到网站的搜索框
【发布时间】:2015-08-28 22:43:36
【问题描述】:

所以最近我一直在研究我的网站,我想要一种方法,用户可以轻松地从一个网站访问另一个网站,而不会出现混乱的链接。所以我想添加一个文本输入框,这样如果用户输入诸如“论坛”之类的关键字,它将充当单击链接并将他们带到该站点。这是我当前的文本输入框代码。 (PS:我不想用javascript,我只想要html)。

<form action="action_page.php">
Website Search:<br>
<input type="text" name="Website Search" value="website name here">
<br>
<input type="submit" value="Submit">
</form>

感谢您的帮助!

【问题讨论】:

    标签: html forms search input hyperlink


    【解决方案1】:

    没有 javascript 的唯一方法是 php。

    这是一个应该可以工作的示例:

    HTML:

    <form action="action_page.php" method="POST">
    Website Search:<br>
    <input type="text" id="Website Search" name="Website Search" placeholder="website name here">
    <br>
    <input type="submit" value="Submit">
    </form>
    

    action_page.php:

    $word = $_POST["Website Search"];
    $word = strtolower($word); //converts the word to lowercase
    
    $link_forum = ""; //write the link to the pages here
    $link_page1 = "";
    $link_page2 = "";
    
    if ($word == "forum") {
        header("location:".$link_forum); //this redirects you to the page.
    }
    elseif ($word == "page1") {
        header("location:".$link_page1);
    }
    elseif ($word == "page2") {
        header("location:".$link_page2);
    }
    

    只需根据需要添加任意数量的页面,这应该可以正常工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-09
      • 2019-07-05
      • 2023-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-13
      相关资源
      最近更新 更多