2010-10-19 76 views
2

我有一个AjaxControlToolkit.AutoCompleteExtender控件附加到文本框和三个单选按钮。当用户选择一个单选按钮,用于检索在AutoCompleteExtender上市改变的值服务方法,如下所示:强制AutoCompleteExtender下拉列表通过Javascript重新显示

$("#radioButtonList input").click(function() { 

    var selectedValue = $(this).val(); 

    if (selectedValue == 0) { 
     $find('autoCompleteExtender').set_serviceMethod('AutoCompleteExtenderMethod1'); 
    } 
    else if (selectedValue == 1) { 
     $find('autoCompleteExtender').set_serviceMethod('AutoCompleteExtenderMethod2'); 
    } 
    else if (selectedValue == 2) { 
     $find('autoCompleteExtender').set_serviceMethod('AutoCompleteExtenderMethod3'); 
    } 

    $('#textbox').focus(); 
} 

我要确保,如果用户选择一个单选按钮时,文本已经在文本框中显示基于新服务方法的自动完成值列表(就像用户单击单选按钮并在文本框中键入然后一样)。

我曾尝试过各种事件触发机制,比如这个:

var press = jQuery.Event("keypress"); 
press.ctrlKey = false; 
press.which = 77; 
$('#textbox').trigger(press); 

...每一种...

$('#textbox').keydown(); 
$('#textbox').keypress(); 
$('#textbox').keyup(); 

,甚至:

$('#textbox').get(0).value += 'm'; 

但似乎没有任何东西强迫正确的事件触发,以使自动完成列表重新显示新服务方法的结果d。我如何使用Javascript做到这一点?

编辑:我应该注意:jQuery事件在上述每种情况下正确触发,它们只是不会导致自动完成列表在他们这样做时重新出现。我想我还没有发现autocomplexxtender期望强制列表出现的事件的正确组合。

回答

2

确保您绑定$(document).ready()函数中的事件。以下工作正确

 <html> 
     <head> 
     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"> 
      </script> 
      <script> 
      $(document).ready(function(){ 
    $("#radioButtonList input").change(function() { 

     var selectedValue = $(this).val(); 

     if (selectedValue == 0) { 
      $find('autoCompleteExtender').set_serviceMethod('AutoCompleteExtenderMethod1'); 

     } 
     else if (selectedValue == 1) { 
      $find('autoCompleteExtender').set_serviceMethod('AutoCompleteExtenderMethod2'); 

     } 
     else if (selectedValue == 2) { 
      $find('autoCompleteExtender').set_serviceMethod('AutoCompleteExtenderMethod3'); 

     } 
//force click on text box 
    $('#textbox').click() 
     $('#textbox').focus(); 
    }); 
//handle click event 
    $("#textbox").click(function(){ 
    alert("textbox clicked") 
    //handle your refresh action for the textbox here 
    }) 
    }) 

    </script> 
    </head> 
    <body> 
    <input id="textbox" type="text" value="test"> 
    <div id="radioButtonList"> 
    <input type="radio" value="0"> 
    <input type="radio" value="1"> 
    <input type="radio" value="2"> 
    </div> 
    </body> 
    </html> 
+0

绝对如此,和我已经做的事 - 对不起,我应该更清楚。在上述每种情况下,jQuery事件都能正确触发,它们只是不会导致自动完成列表在他们执行时重新出现。我还没有发现autocomplexxtender期望强制列表出现的事件的正确组合。将相应地编辑。 – Bambi 2010-10-20 21:36:42

+0

尝试在自动填充对象上执行showPopup(),例如YourAutoCompleteObject.showPopup()或$ find('autoCompleteExtender')。showPopup在文本框的点击处理程序中。 – Michal 2010-10-20 22:22:31

+1

Ahhhhh,就是这样做的。实际上并没有showPopup()这样做,但是在该领域的进一步调查让我感到_onTimerTick(),单击单选按钮后没有被调用。谢谢! – Bambi 2010-10-21 01:13:28