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. spring-webmvc 4.3.4 与 freemarker、easyui 整合

    一.所需lib包 二.web.xml配置 <?xml version="1.0" encoding="UTF-8"?> <web-app xm ...

  2. (转)innodb 与 myisam 读写性能分析

    前提: mysql在5.0之前,读写性能相差很大,读性能:myisam 很强 mysql在5.0之后,差距不是很大 http://passover.blog.51cto.com/2431658/507 ...

  3. pt-table-checksum 主从复制一致性检查

    1. pt-table-checksum介绍 http://www.percona.com/doc/percona-toolkit/2.2/pt-table-checksum.html pt-tabl ...

  4. java jvm学习笔记九(策略文件)

    欢迎装载请说明出处:http://blog.csdn.net/yfqnihao/article/details/8271407 课程源码:http://download.csdn.net/detail ...

  5. 七牛上传Qt版本

    最近在找图床,写博客啥的需要.以前的图床好像挂了,搭在BAE上的图床也挂了,可能BAE3.0更新了吧. 花了点时间写了Qt版本 github地址:https://github.com/wzyuliya ...

  6. MSP430开学的序章

    吐槽一下最近在搞什么~~~,星期三在等板子来,自己的板子,激动呀!!F5系列的板子,激动呀!结果板子到星期五才拿到!开始的时候,感觉自己没多大问题,结果一上手就问题百出,因为没仔细看用户手册,导致光盘 ...

  7. 【原】理解Storm拓扑的并行

    Storm入门教程 1. Storm基础 Storm Storm主要特点 Storm基本概念 Storm调度器 Storm配置 Guaranteeing Message Processing(消息处理 ...

  8. 【原创】_INTSIZEOF 内存按照int对齐

    #include <stdarg.h> 里面定义了如下宏 #define _INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) & ~(siz ...

  9. homework01

    第一眼看到这个题目的时候就意识到这道题应该使用动态规划来解决,但因代码能力有限,因此从一维的问题开始解决,用C语言编写,代码如下: int maxsum(int *p,int size){ int i ...

  10. Objective-C Runtime 运行时之三:方法与消息

    基础数据类型 SEL SEL又叫选择器,是表示一个方法的selector的指针,其定义如下: typedef struct objc_selector *SEL; objc_selector结构体的详 ...