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. c语言关键字总结

    1.关键字变更历史 1999年12月16日,ISO推出了C99标准,该标准新增了5个C语言关键字: inline restrict _Bool _Complex _Imaginary(注意bool 从 ...

  2. word2010中莫名出现灰色中括号解决方案

    灰色中括号[]是文中书签,解决方案: word 文件-选项-高级,在“显示文档内容”部分,去掉“显示书签”前面的勾选.

  3. jsp、js、html等

    1.一个button标签怎么触发事件: 一般触发事件有两种方式,要么是在html直接绑定,即button标签中不只有class.type和id,还要写onclick=... 还有一种,就是在js代码部 ...

  4. HDU 5624 KK's Reconstruction 最小生成树

    题意:这是bc round 71 div 1 的 1004 直接去看中文题意 分析: 首先,一种合法方案对应了原图的一棵生成树. 我们知道,最小生成树有一个性质是最大边最小. 因此,我们可以枚举生成树 ...

  5. js 数组常用方法说明

    //push 向数组最后添加一项 var arr = ['one', 'two', 'three']; arr.push("four"); console.log(arr);//[ ...

  6. 使用asp.net MVC4中的Bundle遇到的问题及解决办法

    背景 之前有过使用MVC3的经验,也建过MVC4的基本样例看过,知道有bundle这么一个方法. 近日想建个网站使用MVC4,但是我觉得在基本样例上改不好,有太多无用的东西,所以就建了一个空白的MVC ...

  7. git和repo入门

    版本控制 版本控制是什么已不用在说了,就是记录我们对文件.目录或工程等的修改历史,方便查看更改历史,备份以便恢复以前的版本,多人协作... 一.原始版本控制 最原始的版本控制是纯手工的版本控制:修改文 ...

  8. 单点登录sso规范

    http://jasig.github.io/cas/development/protocol/CAS-Protocol-Specification.html

  9. 教程-Delphi第三方控件安装卸载指南

    1 只有一个DCU文件的组件.DCU文件是编译好的单元文件,这样的组件是作者不想把源码公布.一般来说,作者必须说明此组件适合Delphi的哪种版本,如果版本不对,在安装时就会出现错误.也正是因为没有源 ...

  10. hdu 2716 Message Decowding

    Message Decowding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...