【问题标题】:How can I allow someone to add to the url in a text box? [closed]如何允许某人添加到文本框中的 url? [关闭]
【发布时间】:2013-04-04 02:38:27
【问题描述】:

我确定这是在线的某个地方,在 Google 上搜索了一个小时后,我什么也没找到。我正在尝试在(例如)site.com 上使用 HTML 来创建一个文本框,当您按下 sumbit 时,它会将您带到 sitetwo.com/enteredtext。我会非常感谢任何能指出我正确方向的人..

【问题讨论】:

  • 让表单处理脚本使用Location: 标头发送重定向。
  • 您是否在项目中使用任何其他语言(代码隐藏,例如 C#)?

标签: html submit refer


【解决方案1】:
<?php
    if(isset($_GET['enteredtext'])){
        header("Location: sitetwo.com/" . $_GET['enteredtext']);
    }
?>

或javascript

$('form').submit(function(){
    window.location.href = "www.sitetwo.com/" + $('#enteredtext').val();
    //you might need to encodeURI($('#enteredtext').val()); to escape characters
});

您的 html 需要输入 idnameenteredtext 之类的

<input type="text" id="#enteredtext" name="enteredtext" placeholder="some value to display in text box" />

【讨论】:

    【解决方案2】:

    在 PHP 中:

    <?php
    header("Location: http://sitetwo.com/" . $_REQUEST['enteredtext']);
    

    【讨论】:

      【解决方案3】:

      javascript可以设置this的值

      window.location.assign("site.com/"+document.getElementById('myInput').value);
      

      虽然我建议对文本条目进行某种类型的验证。

      查看http://jsfiddle.net/y3TuP/

      【讨论】:

      • 嗯,我第一次看到window.location.assign...
      猜你喜欢
      • 2023-03-25
      • 2013-02-19
      • 1970-01-01
      • 2019-02-09
      • 2021-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多