Ajax suggest(jquery) 代码

var oInputField;   
var oPopDiv;       
var oColorsUl;
var oopField;
//var url="http://localhost/zentrack/rpc.php";
//alert(‘i am here’);
function initVars(field){
oopField=field;
oInputField = $("input[name="+field+"]");

//oInputField = $("#colors");
oPopDiv = $("#popup");
oColorsUl = $("#colors_ul");
}
function clearColors(){

oColorsUl.empty();
oPopDiv.removeClass("show");
}
function setColors(the_colors){

clearColors();   
oColorsUl.css("background-color","#EEEE11");
//oPopDiv.css("background-color","silver");
oPopDiv.addClass("show");
for(var i=0;i<the_colors.length;i++)

oColorsUl.append($("<li>"+the_colors[i]+"</li>"));
oColorsUl.find("li").click(function(){
oInputField.val($(this).text());
clearColors();
if(oopField==’system_id’){
//alert(oopField);
//$("input[name="+oopField+"]").readOnly=true;
//document.forms[‘ticketForm’].system_id.readOnly=true;
oInputField.readOnly=true;
}
}).hover(
function(){$(this).addClass("mouseOver");},
function(){$(this).removeClass("mouseOver");}
);

}

function findColors(pField){
initVars(pField);   

if(oInputField.val().length > 0){
oInputField.css("background","url(‘css/yui/folder/progress1.gif’) repeat-y" );   
oInputField.css("background-position","right");
$.get(url,{sColor:oInputField.val(),field:oopField},
function(data){
var aResult = new Array();
//alert(data.status);
if(data!=='{"status":"false"} ‘&& data.length > 1){

aResult = data.split(",");
//alert(aResult);
setColors(aResult);   
oInputField.css("background","" ) ;   
}
else
clearColors();
oInputField.css("background","" ) ;   
});
}
else
clearColors();   
}
function findColors2(pField){
initVars(pField);   

if(oInputField.val().length > 0){
oInputField.css("background","url(‘css/yui/folder/progress1.gif’) repeat-y" );   
oInputField.css("background-position","right");
$.getJSON(url,{sColor:oInputField.val(),field:oopField},
function(data){   

if(data.status!==’false’&&data.length>=1){   
//alert(‘fff’);
//aResult = data.split(",");
setColors2(data);   
oInputField.css("background","" );   
}
else{

clearColors();
oInputField.css("background","" );   
}

});
}
else
clearColors();   
}
function setColors2(the_colors){

clearColors();   
oColorsUl.css("background-color","#EEEE11");
//oPopDiv.css("background-color","silver");
oPopDiv.addClass("show");
for(var i=0;i<the_colors.length;i++)

oColorsUl.append($("<li title=’"+the_colors[i].num+"’>"+the_colors[i].title+"</li>"));
oColorsUl.find("li").click(function(){
oInputField.val($(this).text());
//alert($(this).attr("title"));
$("input[name=system_id]").val($(this).attr("title"));

clearColors();
if(oopField==’system_id’){
//alert(oopField);
//$("input[name="+oopField+"]").readOnly=true;
//document.forms[‘ticketForm’].system_id.readOnly=true;
oInputField.readOnly=true;
}
}).hover(
function(){$(this).addClass("mouseOver");},
function(){$(this).removeClass("mouseOver");}
);

}

发表评论

邮箱地址不会被公开。 必填项已用*标注