我正在与http://easyautocomplete.com/合作。它工作正常,但当我尝试禁用select on click时,它无法正常工作。
当我尝试在onClickEvent/onChooseEvent
上停用默认操作时,它会显示Uncaught TypeError: Cannot read property 'preventDefault' of undefined
。
我无法弄清楚event.preventDefault();
无效的原因。我不是专家。只是为了学习目的。
var options = {
data: [ {name: "Avionet", spec: "air", code: "47201", price: "£120"},
{name: "Car", spec: "ground", code: "47201S", price: "£120"},
{name: "Motorbike", spec: "ground", code: "47203", price: "£120"},
{name: "Plain", spec: "air", code: "4721", price: "£120"},
{name: "Train", spec: "ground", code: "47253", price: "£120"}
],
getValue: "name",
list: {
match: {
enabled: true
},
onClickEvent: function(event) {
event.preventDefault();
}
},
template: {
type: "custom",
method: function(value, item) {
return '<div class="cbs-subject-name">'+ value +'</div><div class="cbs-subject-price"><span class="cbs-meta-icon cbs-meta-icon-price"></span> '+item.price+' </div><div class="cbs-subject-spec"><span class="cbs-meta">Specification:</span> '+item.spec+' </div><div class="cbs-subject-code"><span class="cbs-meta">Entry Code:</span> '+item.code+' </div>';
}
}
};
$("#awesomplete").easyAutocomplete(options);
感谢您的时间。 :)
答案 0 :(得分:0)
它不起作用的原因是easyautocomplete调用onClickEvent()但不传递任何内容,因此event参数为null。
我认为你实际上不能在这个函数中改变库的功能。它将继续并在输入框中填入用户选择的项目。