javascript - how to attach on to the `onclick` event of the link? (autocomplete) -
do autocomple. need in dropdown prompts make links.
i use plugin.
$(function () { $('input[name="oem"]').autocomplete({ minchars: 4, source: function (term, response) { term = term.tolowercase(); $.getjson('/search.json?oem=' + term, function (data) { var matches = []; (i = 0; < data.length; i++) if (~data[i].tolowercase().indexof(term)) matches.push(data[i]); response(matches.slice(0, 11)); }); }, renderitem: function (item, search) { search = search.replace(/[-\/\\^$*+?.()|[\]{}]/g); var re = new regexp("(" + search.split(' ').join('|') + ")"); return '<div class="autocomplete-suggestion" data-val="' + item + '"><a href="#" onclick="javascript:document.location.href="#"">' + item.replace(re, "<b>$1</b>") + '</a></div>'; } }); });
how attach on onclick
event of link?
there other variants?
below, have changed way building return string in code,
return "<div class='autocomplete-suggestion' data-val='" + item + "'><a href='#' onclick='javascript:document.location.href="+\""+"#"+\""+">" + item.replace(re, "<b>$1</b>") + "</a></div>";
Comments
Post a Comment