我有一个aspx页面和一个asp文本框控件,它具有ajax autoCompleteExtender。我希望根据自动完成列表中选定的元素将页面重定向到其他页面。但是当我使用window.location()在.aspx页面不工作
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>
的脚本工作,我想它像
警报( “City.aspx城市=?” +城市+ “ - ” +国家)
有没问题。但是当我想重定向到该页面时,它不起作用。我也试过
window.location的( “http://www.google.com”)
它不工作为好。
可能是什么问题?
**在您的JavaScript控制台中阅读** [文档](https://developer.mozilla.org/en/DOM/window.location)和** look **。 'location'不是一个函数。 'location.href'不是一个函数。对于这些查询参数,您可能还需要使用['encodeURIComponent'](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/encodeURIComponent),并且没有替换('/','' +')'虚弱。 –