这是我的HTML代码
<form method="get" action="https://example.com/i">
Username : <input type="text" name="uname"></input>
<br/>
<input type="submit" value="search"></input>
</form>
&#13;
当我在其中搜索某些内容时,它会重定向到example.com/i/username/?
,但我希望将其重定向到example.com/i/username
。网址末尾不应有/
和?
答案 0 :(得分:0)
这里是要走的路......
var search = document.getElementById('search');
search.addEventListener('click', function() {
var name = document.getElementById('name');
//Redirect the client to the desired URL, if the name is valid.
location.href = 'https://example.com/i/' + encodeURIComponent(name.value);
});
&#13;
<form method="get" action="https://example.com/i" id="myForm">
Username : <input type="text" id="name"></input><br/>
<input type="button" value="search" id="search"></input>
</form>
&#13;