如果 jquery ui 内的条件自动完成
If condition inside jquery ui autocomplete
$(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 代码
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
$(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 代码
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