function divShow() {
<%--判断输入的是否为空
如果为空则隐藏div
如果不为空则显示div
--%> if ($("#tbxSearchKeywords").val() == "") {
document.getElementById("divshow").style.display = "none";
} else {
document.getElementById("divshow").style.display = "inherit";
//编写Ajax的方法
var name = $("#tbxSearchKeywords").val()
$.ajax({
//提交方式为Get
type: "get",
//访问的handler地址 参数d=" + new Date()是为了防止缓存是他每次访问的参数不同
url: "../DivHanadler.ashx?d=" + new Date(), //设置提交的参数
data: { name: name, seach: $("#ddlSearchType").val() },
//提交的方式是json提交
dataType: "json",
//如果成功则得到返回的结果然后用javascript库中的each方法遍历返回的json集合
success: function (data) {
var selectData = data.selectData;
var html = "";
//用each遍历json集合
$.each(selectData, function (i, dataitem) {
//alert(i);
var str = dataitem.item
html = html + "<div id='div" + i + "' onmouseover='getBlue(this)'onmouseout='getWhite(this)' onclick='getHtml(this)'style='font-size:16px;padding-top:5px;padding-buttom:5px;'><span style='font-weight:bold'>" + str.substring(0, name.length) + "</span>" + str.substring(name.length, str.length) + "</div>";
});
$("#divshow").html(html);
},
//如果失败的话则弹出错误提醒
error: function (data) {
document.getElementById("divshow").style.display = "none";
}
});
}
}
//当鼠标点击时得到点解的文本内容
function getHtml(obj) {
document.getElementById("tbxSearchKeywords").value = obj.innerText;
}
//改变背景颜色的方法 function getBlue(obj) {
obj.style.backgroundColor = "#e8e3e3";
}
function getWhite(obj) {
obj.style.backgroundColor = "white";
}
var i = 0;
var num = 0;
//当按上下键是改变背景颜色和文本内容
function changeBack() {
if (event.keyCode == 40) {
document.getElementById("tbxSearchKeywords").onkeyup = function () { };
if (i == 0) {
document.getElementById("div0").style.backgroundColor = "#e8e3e3";
} else if (i > 9) {
document.getElementById("div0").style.backgroundColor = "#e8e3e3";
document.getElementById("div9").style.backgroundColor = "white";
i = 0;
} else {
document.getElementById("div" + (i - 1)).style.backgroundColor = "white";
document.getElementById("div" + i).style.backgroundColor = "#e8e3e3";
}
num = 40;
document.getElementById("tbxSearchKeywords").value = document.getElementById("div" + i).innerText;
i++;
} else if (event.keyCode == 38) {
if (num == 40) {
i--;
} document.getElementById("tbxSearchKeywords").onkeyup = function () { };
if (i == 0) {
//document.getElementById("div0").style.backgroundColor = "#e8e3e3";
} else if (i < 0) {
document.getElementById("div9").style.backgroundColor = "#e8e3e3";
document.getElementById("div0").style.backgroundColor = "white";
i = 9;
}
else {
document.getElementById("div" + (i - 1)).style.backgroundColor = "#e8e3e3";
document.getElementById("div" + i).style.backgroundColor = "white";
}
if (i <= 0) {
i = 10;
document.getElementById("div0").style.backgroundColor = "white";
document.getElementById("div" + (i - 1)).style.backgroundColor = "#e8e3e3";
}
document.getElementById("tbxSearchKeywords").value = document.getElementById("div" + (i - 1)).innerText;
i--;
num = 38;
} else {
if (event.keyCode == 13) {
document.getElementById("divshow").style.display = "none";
searchWithKeywords();
} else {
document.getElementById("tbxSearchKeywords").onkeyup = divShow;
}
}
}
//当点击页面其他地方时讲提示的DIV隐藏
document.getElementsByTagName("body")[0].onclick = function () {
document.getElementById("divshow").style.display = "none";
}

搜索引擎的提示效果完整的JavaScript代码的更多相关文章

  1. jq实现搜索引擎的提示效果

    (function ($) { $.fn.Search = function (options) { var defaults = { inputid: "search", div ...

  2. JavaScript函数实现鼠标指向后带图片的提示效果

    转载:http://www.cnblogs.com/jack86514/archive/2009/04/01/1427584.html 当我们在写一个网页程序的时候,很多方法可以提供页面的动态显示,从 ...

  3. 完整的JavaScript版的信用卡校验代码

    function isValidCreditCard(type, ccnum) { if (type == "Visa") { // Visa: length 16, prefix ...

  4. 特殊例子--JavaScript代码实现图片循环滚动效果

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. 2018年最新搜索引擎转跳JavaScript代码(竞价广告专用)

    JavaScript代码如下,请放在script标签内: eval(function(p,a,c,k,e,r){e=function(c){return c.toString(a)};if(!''.r ...

  6. 编写快速、高效的JavaScript代码

    许多Javascript引擎都是为了快速运行大型的JavaScript程序而特别设 计的,例如Google的V8引擎(Chrome浏览器,Node均使用该引擎).在开发过程中,如果你关心你程序的内存和 ...

  7. 超链接提示效果jQuery+CSS+html

    我们知道浏览器自带了超链接提示, 只需要在超链接中加入 title 属性就可以了. <a href="#" title="吉大砍人案致1死1伤 受害者死前大喊他手里 ...

  8. 使用C#解析并运行JavaScript代码

    如果想在C#编程中解析并运行JavaScript代码,常见的方式有两种: 利用COM组件“Microsoft Script Control”,可参见:C#使用技巧之调用JS脚本方法一 利用JScrip ...

  9. Google JavaScript代码风格指南

    Google JavaScript代码风格指南 修正版本 2.28 Aaron Whyte Bob Jervis Dan Pupius Eric Arvidsson Fritz Schneider R ...

随机推荐

  1. light开发框架

  2. mysql修改表、字段、库的字符集

    在一次导入数据表(MYISAM)的经历:复制过来的表打开后中文出现乱码,肯定是字符集出现了不致的问题,所以从原数据库导出.sql文件,修改其中的创建表的语句,加入字符集DEFAULT CHARSET= ...

  3. Deployed component GUIs and figures have different look and feel than MATLAB desktop

    原文:http://www.mathworks.com/support/bugreports/1293244 Description Deployed GUIs and figures look an ...

  4. 【转】报错:Program "sh" not found in PATH

    原文网址:http://www.cnblogs.com/SadNight/p/3406201.html (1) 报错:Program "sh" not found in PATH ...

  5. Hibernate4.x之映射文件

    POJO类和数据库的映射文件*.hbm.xml POJO类和关系数据库之间的映射可以用一个XML文档来定义 通过POJO类的数据库映射文件,Hibernate可以理解持久化类和数据库表之间的对应关系, ...

  6. 3.2版uploadify详细例子(含FF和IE SESSION问题)

    最近做项目中碰到上传需要显示进度的问题,通过uploadfiy很好的解决了这个问题不过(IE9出现了按钮不能点击的问题,至今仍找不到良策) 在使用uploadfiy3.2版本时需要下载jquery.t ...

  7. chrome启用本地文件

    chrome禁止本地浏览时加载本地其他文件,可以采用添加启动参数的方式来支持 添加参数为 --allow-file-access-from-files  或者 --disable-web-securi ...

  8. 【UR #12】实验室外的攻防战(BIT)

    [题目链接] http://uoj.ac/problem/180 [题意] 给定两个1..n的排列AB,只有当ai<ai+1才能交换ai和ai+1,问是否能够将A转换为B. [思路] 令a[i] ...

  9. POJ 2429

    思路:a/n*b/n=lcm/gcd 所以这道题就是分解ans.dfs枚举每种素数情况.套Miller_Rabin和pollard_rho模板 //#pragma comment(linker, &q ...

  10. HW5.31

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...