Javascript window.location()在.aspx页中不起作用

Javascript window.location()在.aspx页中不起作用,javascript,Javascript,我有一个aspx页面和一个asp文本框控件,其中包含ajax AutoCompleteXtender。我希望根据自动完成列表中选定的元素将页面重定向到另一个页面。但是当我使用 window.location() 没有发生任何事情,只是刷新了相同的页面。这是我的javascript <script type="text/javascript"> function selectCity() { var str = document.getElementById(

我有一个aspx页面和一个asp文本框控件,其中包含ajax AutoCompleteXtender。我希望根据自动完成列表中选定的元素将页面重定向到另一个页面。但是当我使用

window.location()
没有发生任何事情,只是刷新了相同的页面。这是我的javascript

<script type="text/javascript">
    function selectCity() {
        var str = document.getElementById('<%= txtSearchForDestination.ClientID %>').value;
        var array = str.split(",");
        var city = array[0].replace(/^\s\s*/, '').replace(/\s\s*$/, '');
        city = city.replace(/ /g, "+")
        var country = array[1].replace(/^\s\s*/, '').replace(/\s\s*$/, '');
        country = country.replace(/ /g, "+")
        window.location.href("City.aspx?city=" + city + "-" + country);
    }
</script>

函数selectCity(){
var str=document.getElementById(“”).value;
var数组=str.split(“,”);
var city=array[0]。替换(/^\s\s*/,“”)。替换(/\s\s*$/,“”);
city=city.replace(//g,“+”)
var country=array[1]。替换(/^\s\s*/,“”)。替换(/\s\s*$/,“”);
country=country.replace(//g,“+”)
window.location.href(“City.aspx?City=“+City+”-“+country”);
}
脚本正在运行,我试了一下

警报(“City.aspx?City=“+City+”-“+country”)

没问题。但当我想重定向到该页面时,它不起作用。我也试过了

窗口位置(“http://www.google.com))

它不起作用了

有什么问题吗?

您是否尝试过:

  window.location = 'City.aspx?city=' + city + '-' + country;

它不是一个函数,而是一个属性

window.location.href = "City.aspx?city=" + city + "-" + country;

阅读并查看JavaScript控制台<代码>位置不是一项功能<代码>位置。href不是一个函数。您可能还需要对这些查询参数使用,并且所有这些都不是
replace(//g,“+”)
sillity.omg是的,它现在正在工作!我试着用妄想症做一个小时!谢谢,当然谢谢。。我认为这是工作时间过长的结果。