prototype笔记

注意在observe时候一定要传方法名,方法不能有括号!!!

自制土b autocomplete
var inputFeild_names;
var table_name_table;
var tbody_name_table_body;
var div_popup;
var query;

function findNames(){
var url = 'AjaxSample.action';
var params = "input="+$('names').value;
var getName = new Ajax.Request(
url,
{ parameters:params,
onComplete: findNameCallback,
});
}
function findNameCallback(transport){
var breeds = transport.responseJSON;
var breedArray = breeds.breeds;//save all the breeds from the server
var matchArray = new Array();// save matching results
query = $('names').value;

breedArray.each(//if match the query, add it
function(item){
if(item.include(query)){
matchArray.push(item);
}
}
);

if(Object.isArray(matchArray))//start to append the matched query
{
matchArray.each(function(item){
var cell = new Element('td').update(item);
var row = new Element('tr').update(cell);
$(cell).observe('mouseOver',function(){
$(cell).className='mouseOver';
});
$(cell).observe('mouseOut',function(){
$(cell).className='mouseOut';
});
$('name_table_body').appendChild(row);
var breakpoint = "break";
});
}
}

你可能感兴趣的:(Ajax,prototype)