当前位置: 代码迷 >> JavaScript >> 如其写一个JS搜索去变量的
  详细解决方案

如其写一个JS搜索去变量的

热度:173   发布时间:2013-11-13 14:04:18.0
如果写一个JS搜索去变量的
<form action="/search/">
<input class="keyword" name="key" id="key" onblur="soH('key');" onfocus="soT('key');" value=""/>
<button>搜索</button>
</form>

如例我想达到的效果:http://127.0.0.1/search/我想搜索的内容

这样提交时出现了http://127.0.0.1/search/?key=我想搜索的内容

怎么去掉?key=

------解决方案--------------------
<form action="/search/">
<input class="keyword" name="key" id="key" onblur="soH('key');" onfocus="soT('key');" value=""/>
<button  onclick="return doSearch();">搜索</button>
</form>


<script type="text/javascript">
    function doSearch(){
        var a=document.getElementById("key").value;
        window.location.href='/search/'+encodeURIComponent(a);
    }
</script>
  相关解决方案