-2

aspx ページと ajax autoCompleteExtender を持つ asp テキスト ボックス コントロールがあります。オートコンプリート リストから選択した要素に従って、ページを別のページにリダイレクトしたい。しかし、私が使用するとき

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>

スクリプトは機能しています。

alert("City.aspx?city=" + 都市 + "-" + 国)

問題はない。しかし、そのページにリダイレクトしたいときは機能しません。私も試しました

window.location("http://www.google.com")

それもうまくいきません。

何が問題になる可能性がありますか?

4

2 に答える 2

2

関数ではなく、プロパティです。

window.location.href = "City.aspx?city=" + city + "-" + country;
于 2012-05-02T00:21:11.003 に答える
1

やってみました:

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

?

于 2012-05-02T00:19:40.163 に答える