【问题标题】:If condition inside jquery ui autocomplete如果jquery ui自动完成中的条件
【发布时间】:2016-08-22 11:18:49
【问题描述】:
$(function() {
var services = [      
  "Water Wash",
  "Tyre Puncture"      
];
var servicesCar = [      
  "Car Wash",
  "Tyre Puncture",
  "Vehicle Diagonstics",
  "Other Repairs",
];
$('#ServiceType').autocomplete({
    if($('#VehicleType').val() == '4w') {
        source: servicesCar,
        minLength: 0,
        scroll: true
   }
  else {
        source: services,
        minLength: 0,
        scroll: true
    } }).focus(function() {
        $(this).autocomplete("search", "");
});
});

我需要检查选项值是2w 还是4w,并根据该值显示源标签。但是,这段代码不会自动完成输入

<select id="VehicleType" name="VehicleType">
  <option value="2w"> Bike </option> 
  <option value="4w"> Car </option> 
</select>

这是我的 HTML 代码

【问题讨论】:

  • 请提及您遇到的问题
  • @AnoopLL 它不会自动完成其中的if 条件,而我需要检查条件然后发送源标签
  • 需要在车辆类型的onChange里面写自动补全代码。
  • 我不需要在更改选项时调用自动完成功能。我只需要获取当前选择的值并根据该@AnoopLL 发送标签

标签: jquery jquery-ui autocomplete jquery-ui-autocomplete


【解决方案1】:

HTML

<select id="VehicleType" name="VehicleType">
  <option value="2w"> Bike </option> 
  <option value="4w"> Car </option> 
</select>

<input type="text" id="ServiceType" /> 

JS

$(function() {
var services = [      
  "Water Wash",
  "Tyre Puncture"      
];
var servicesCar = [      
  "Car Wash",
  "Tyre Puncture",
  "Vehicle Diagonstics",
  "Other Repairs",
];

$( "#ServiceType" ).focusin(function() {
        if($('#VehicleType').val() == '4w') {
                $('#ServiceType').autocomplete({
            source: servicesCar,
            minLength: 0,
            scroll: true
        });        
   }
  else {
            $('#ServiceType').autocomplete({
            source: services,
            minLength: 0,
            scroll: true
        });  
    }    
        });
});

参考Fiddle

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-02-06
    • 2012-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-23
    相关资源
    最近更新 更多