0

代码如下

<select name ="dept" id="dept">
   <option value="1">Software</option>
   <option value="2">Marketing</option>
</select>

<input name="section_name" id="section_name" type="text">
<input name="emp_id" id="emp_id" type="text">

Jquery代码如下

$(document).ready(function() {
$('#section_name').keydown(function(){
    $(this).autocomplete({
        source: "<?php echo base_url(); ?>index.php/search_con/section_name",
        minLength: 0,
        autoFocus: true,
        select: function(event, ui)
        {
        }
    });
  });   
$('#emp_id').keydown(function(){
    $(this).autocomplete({
        source: "<?php echo base_url(); ?>index.php/search_con/emp_id",
        minLength: 0,
        autoFocus: true,
        select: function(event, ui)
        {
        }
    });
  });

});

基本上我希望当我选择部门下拉列表时,它会在部分名称中自动完成,当在自动完成部分名称中搜索部分名称并选择然后这里将出现 emp_id 自动完成,我将搜索 Emp ID。

其他方式我可以说,它将是部门名称下的部门名称和部门名称下的emp_id。

我怎样才能成功解决,请帮助我。

4

1 回答 1

2

根据需要制作两个隐藏字段或两个变量,但我会用变量来做

当用户选择某个部门时,您应该告诉服务器在该部门中进行搜索,因此您需要修改您的 BE 代码,以便实现此目的

var current_department = ""; 

var current_lang = ""; 

//this will be called when ever the select changed 

$('#dept').change(function(){
current_department =  $(this).find(":selected").text();
}); 

在部门自动完成中,您需要在此处发送变量,它将发送您可以设置的部门名称,val()而不是由text()您决定

现在自动完成现在应该这样

$('#section_name').keydown(function(){
    $(this).autocomplete({
        source: "<?php echo base_url(); ?>index.php/search_con/section_name/"+current_department,
        minLength: 0,
        autoFocus: true,
        select: function(event, ui)
        {
               //here you need to tell the next autocomplete what lang you selected e.g. PHP 
              current_lang = ui.item.value; //or .text it's up to you 
        }
    });
  });   

所以下一个自动完成应该是这样的

$('#emp_id').keydown(function(){
    $(this).autocomplete({
        source: "<?php echo base_url(); ?>index.php/search_con/emp_id/"+current_lang,
        minLength: 0,
        autoFocus: true,
        select: function(event, ui)
        {
        }
    });
  });

});

请记住修改您的服务器端代码,我希望这可以帮助您:)

于 2013-02-01T20:48:42.630 回答