jQuery自动完成组合框-自动调整大小

| 我正在使用jQuery自动完成组合框。我希望它可以自动调整为与要替换的下拉列表相同的大小。相反,当前它只是默认为一种宽度,而不是内容宽度(默认情况下是html下拉列表)。 谢谢你的帮助...     
已邀请:
        这是我的自动填充的“打开”选项,具有自动调整大小(自动宽度):
            open: function(e,ui) {
                var autoData = $(this).data(\'autocomplete\');
                var reserText = \",de,del,el,la,las,los,en,\";

                autoData.menu.element.css({\'width\':\'\' + anchoMinimo + \'px\'});

                autoData.menu.element.find(\'li\').each(function() {
                   var fila = $(this);
                   var texto = fila.text().toLowerCase().replace(autoData.term.toLowerCase(), \"<b>\" + autoData.term.toLowerCase() + \"</b>\");
                   var autoText = \"\";

                   texto = texto.split(\" \");

                   for( i = 0; i < texto.length; i++){

                       if((reserText.indexOf( texto[i].replace(\"<b>\",\"\").replace(\"</b>\",\"\") ) != \"-1\") && (i > 0)){
                           autoText += texto[i] + \" \";
                       }else if( texto[i].substring(0,3) == \"<b>\" ){
                           autoText += \"<b>\" + texto[i].charAt(3).toUpperCase() + texto[i].substring(4) + \" \";
                       }else{
                           autoText += texto[i].charAt(0).toUpperCase() + texto[i].substring(1) + \" \";
                       }
                   }

                   autoText = autoText.replace(\" De \",\" de \").replace(\" Del \",\" del \").replace(\" Los \",\" los \").replace(\" El \",\" el \").replace(\" En \",\" en \").replace(\" La \",\" la \").replace(\" Las \",\" las \");

                   fila.find(\'a\').text(\"\");
                   fila.find(\'a\').append( autoText );

                   // Ahora vamos a calcular el ancho de la cadena más ancha para saber qué ancho tiene que tener el combo.
                   ancho = autoText.length * 5; // Con esta fuente de letra, en IE, etc...

                   if(ancho > anchoFilaDestinos){
                       anchoFilaDestinos = ancho;
                   }
                   // Fin del cálculo del ancho.

                   fila.find(\'a\').css({\'white-space\':\'nowrap\',\'width\':\'276px\',\'text-align\':\'left\'});

                   if( fila.index()%2 > 0 ){
                       fila.find(\'a\').css({\'background-color\':\'#EFEFEF\'});   
                   }
                }
请参阅“ // Ahora vamos a calora el ancho de la cadenamásancha para saberquéancho tiene que tener el combo”的部分。 希望这对您有所帮助。     
        我已经针对这种情况提交了答案,在这种情况下,当启动的组合框的大小调整为选择列表的宽度时,它们将被替换。 试试这个链接到另一个线程。 它使用选择元素的宽度而不是列表中的文本。 我还能够使用处理document.body字体大小更改的功能来扩展它。 问候。     

要回复问题请先登录注册