HTML
Lisa autor
Kustutamine: paremklikk autori väljal
PHP fail, mis otsib kirjeid
suggest_author.php lähtekood:
if (strlen($_REQUEST['q']) <= 0) exit;
$authors = array(0 => 'John Digweed', 1 => 'Pamela Alemap', 7 => 'Kevin Constner', 8 => 'Abraham Lincoln');
$matches = preg_grep('/'.$_REQUEST['q'].'/i', $authors);
foreach ((array)$matches as $id => $name) {
$output .= "$id|$namen";
}
if ($output == '') {
echo 'Not found';
} else {
echo $output;
}
Javascript
jQuery(document).ready(function(){
jQuery(".author").autocomplete("/snippets/autocomplete/suggest_author.php", {assignToName:'authors[]', minChars:1, matchSubset:0, matchContains:0, cacheLength:10, onItemSelect:selectItem, formatItem:formatItem, selectOnly:1 });
});
jQuery('.author').on('contextmenu', function (e) {
e.preventDefault();
if (confirm('Remove author '+jQuery(this).val()+'?')) {
jQuery(this).remove();
}
});
function addAuthor(where) {
var el = jQuery('');
jQuery(where).append(el);
el.autocomplete("/snippets/autocomplete/suggest_author.php", {assignToName:'authors[]', minChars:1, matchSubset:0, matchContains:0, cacheLength:10, onItemSelect:selectItem, formatItem:formatItem, selectOnly:1 });
el.on('contextmenu', function (e) {
e.preventDefault();
if (confirm('Remove author '+jQuery(this).val()+'?')) {
jQuery(this).remove();
}
});
el.focus();
}
CSS
Inkluudi jquery.autocomplete.css
Kogu demo allalaadimiseks
Lae alla .zip fail