/** * 焦点查询关键词 * * @param {type} keyword * @returns {undefined} * * @Author guan */ function lookup(keyword) { //var category_list = document.getElementById('category'); var suggestions = document.getElementById('suggestions'); var category = '全部'; if(keyword.length == 0) { //隐藏建议框 suggestions.style.display = 'none'; } else { $.ajax({ url: "suggestions.php", type: "post", data:'keyword='+ keyword, success: function(data,textStatus){ //$('#divtest').css('background', 'yellow').html(data).show(); if(data) { $("#suggestions").css('display', 'block'); $("#auto_suggestions_list").html(data); }else{ $("#suggestions").css('display', 'none'); } //$("#divtest2").html(data); }, error: function(o){ // alert(o.responseText); } }); } document.documentElement.onkeyup = keyup; } /** * 按键查询关键字 * * @type Number|Number|Number|@exp;li@pro;length * * @author guan */ index = 0; //初始化索引 function keyup(e) { var keyword = document.getElementById('keyword').value; var suggestions = document.getElementById('suggestions'); var category_list = document.getElementById('category'); //var category = category_list.options[category_list.selectedIndex].value; e = window.event || e; if(40 == e.keyCode) //按键盘向下键 { var li = document.getElementById('suggestions_list_id').getElementsByTagName('li'); if(index == 0 && document.getElementById('keyOne').value == 1) { index = -1; document.getElementById('keyOne').value = 0; } if(++index == li.length) { index = 0; } setView(li, index, li[index].title); } else if(38 == e.keyCode)//按键盘向上键 { var li = document.getElementById('suggestions_list_id').getElementsByTagName('li'); if(--index == -1) { index = li.length-1; } setView(li, index, li[index].title); } else { if(keyword.length == 0) { //隐藏建议框 suggestions.style.display = 'none'; } else { $.ajax({ url: "suggestions.php", type: "post", data:'keyword='+ keyword, success: function(data,textStatus){ //$('#divtest').css('background', 'yellow').html(data).show(); if(data) { $("#suggestions").css('display', 'block'); $("#auto_suggestions_list").html(data); } //$("#divtest2").html(data); }, error: function(o){ // alert(o.responseText); } }); } } } function change_suggestions_response(res) { var suggestions = document.getElementById('suggestions'); var auto_suggestions_list = document.getElementById('auto_suggestions_list'); if(res.option) { suggestions.style.display = 'block'; auto_suggestions_list.innerHTML = res.option; } else { auto_suggestions_list.innerHTML = 'error'; } } /** * 设置背景颜色 * * @param {string} elems * @param {string} index * @returns {undefined} * * @Author guan */ function setView(elems, index, str) { var input_obj = document.getElementById('keyword'); for(var j=0; j]+>/g,""); //for(var i=0, len=str.length; i