Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 使用GET方法重定向时向URL添加引号_Html_Forms_Get - Fatal编程技术网

Html 使用GET方法重定向时向URL添加引号

Html 使用GET方法重定向时向URL添加引号,html,forms,get,Html,Forms,Get,我有一个如下所示的搜索表单: <form action='http://localhost:1000/' method='GET'> <input name="searchTerm" type="search"> <button type="submit">Search</button> </form> 搜寻 比方说,我搜索单词test,搜索表单会将我重定向到: 相反,我想在搜索词周围加上引号-在本例中为test,如下

我有一个如下所示的搜索表单:

<form action='http://localhost:1000/' method='GET'>
   <input name="searchTerm" type="search">
   <button type="submit">Search</button>
</form>

搜寻
比方说,我搜索单词test,搜索表单会将我重定向到:

相反,我想在搜索词周围加上引号-在本例中为test,如下所示:


有人能帮我做这件事吗

使用JS函数解决了这个问题。代码如下所示:

表格

<form onsubmit="return redirect(this)">
   <input id="searchvalue">
   <button type="submit">Search</button>
</form>

搜寻
JS函数

 <script> 
  function redirect(that) {
  window.location.href = 'http://localhost:1000/' + '?searchTerm=' + '"' + (document.getElementById('searchvalue').value) + '"' 
  return false;
  }
 </script> 

函数重定向(that){
window.location.href=http://localhost:1000/“+”?searchTerm=“+”+(document.getElementById('searchvalue').value)+”
返回false;
}

使用JS函数解决了这个问题。代码如下所示:

表格

<form onsubmit="return redirect(this)">
   <input id="searchvalue">
   <button type="submit">Search</button>
</form>

搜寻
JS函数

 <script> 
  function redirect(that) {
  window.location.href = 'http://localhost:1000/' + '?searchTerm=' + '"' + (document.getElementById('searchvalue').value) + '"' 
  return false;
  }
 </script> 

函数重定向(that){
window.location.href=http://localhost:1000/“+”?searchTerm=“+”+(document.getElementById('searchvalue').value)+”
返回false;
}

为什么?如果您需要在值周围加引号,那么在服务器端代码中添加它们几乎肯定更有意义。因为我想重定向到使用搜索词的外部结果页,同时将它们放在引号之间。如果我不加引号,我将无法正确重定向。为什么?如果您需要在值周围加引号,那么在服务器端代码中添加它们几乎肯定更有意义。因为我想重定向到使用搜索词的外部结果页,同时将它们放在引号之间。如果不添加引号,则无法正确重定向。