簡體   English   中英

jQuery自動完成功能關閉

[英]jQuery autocomplete turn off

第一個問題

我有一個下拉列表,充滿了國家(從xml文件)。

選擇國家/地區后,可以為文本框使用自動填充功能。 此自動完成功能包含來自所選國家/地區的郵政編碼。

現在,我想在dropdownlist.change事件之后立即設置自動完成功能,以防止一個國家​​/地區的自動完成功能(用郵政編碼填充)也適用於另一個國家/地區。 但是,如何關閉它?

碼:

//when changing country, other postcodes will load
        $('[id$=landenDropDown]').change(function () {

            //autocompletes removal
            ...

            $('[id$=POSTCODETextBox]').html("");

            var LandCode = $('[id$=landenDropDown]').attr("value");

            //autocomplete with postal codes for Belgium
            if (LandCode == "BE") {
                //autocomplete postcode from selected country
                $('[id$=POSTCODETextBox]').autocomplete("PostcodeBE.aspx");

            }
             //autocomplete with postal codes for Holland
            else if (LandCode == "NL") {
                //autocomplete postcode from selected country
                $('[id$=POSTCODETextBox]').autocomplete("thingXml.aspx");

            }

            else {
                //test
                getal += 1;
                alert(getal);
            }

問題是,自動完成完成后,選擇了該自動完成仍然存在的其他國家,即使它不必出現也是如此。

請查看文檔:( 文檔)

$( ".selector" ).autocomplete({ disabled: true });

如果此解決方案不適合您,則您可能還會遇到其他問題。 使您的代碼更好一點,也許是引起一些內部錯誤的原因

更改

$('[id$=POSTCODETextBox]').html("");

$('[id$=POSTCODETextBox]').val("");

嘗試為postcodetextbox像這樣工作:

$('[id$=POSTCODETextBox]').autocomplete({
      source: "somesource.aspx",
      change: function(event, ui) {
           $(this).autocomplete("destroy");
      }
});

但這將使用戶無法再次使用它...

您也可以禁用文本框。

$('[id$=POSTCODETextBox]').attr("disabled", "disabled");
    //when changing country, other postcodes will load
    $('[id$=landenDropDown]').bind($.browser.msie ? 'propertychange' : 'change', function () {

        //autocompletes removal
        ...

        var LandCode = $('[id$=landenDropDown]').attr("value");

        $('[id$=POSTCODETextBox]').autocomplete('destroy');

        //autocomplete with postal codes for Belgium
        if (LandCode == "BE") {
            //autocomplete postcode from selected country
            $('[id$=POSTCODETextBox]').autocomplete("PostcodeBE.aspx");

        }
         //autocomplete with postal codes for Holland
        else if (LandCode == "NL") {
            //autocomplete postcode from selected country
            $('[id$=POSTCODETextBox]').autocomplete("thingXml.aspx");

        }

        else {
            //test
            getal += 1;
            alert(getal);
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM