fI'm在开发一个WordPress页面的简单和小的搜索当前URL的一部分:
<script>
function pesquisar()
{
var pesquisar = document.getElementById('termo').value;
var caminho = document.URL+'&pesquisa='+pesquisar;
window.location = caminho;
}
</script>
<input type='text' id='termo'>
<input type='button' value='pesquisar' onclick='pesquisar()'>
所以,搜索的网址是:MYURL /?page_id = 51 & pesquisa = test
当然,page_id是可变的。如果我再次搜索,URL将会是:MYURL /?page_id = 51 & pesquisa = test & pesquisa = new,什么是错的。
我怎样才能得到只使用JavaScript的MYURL /?page_id = 51? window.location.pathname不是我所需要的。
谢谢。
的可能重复[我怎样才能查询字符串值?(http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values) – maerics