|
$(document).ready(function()
|
{
|
//======================== 页面数据 ============================
|
//数据请求地址头
|
var https = 'http://flq.yeshitv.com';
|
//-------------------------------------------------
|
//导航栏相关
|
var index_dao = 0; //导航栏选择下标
|
var show_erweima = false; //是否显示二维码
|
//-------------------------------------------------
|
//输入框组件相关
|
var shuru = ''; //搜索框输入内容
|
var shurulian = []; //联想词的数组
|
var show_liandiv = false; // 是否显示联想框
|
|
|
|
//======================== 组件事件 ============================
|
//顶部按钮点击
|
$(".topdan").click(function()
|
{
|
//获取按钮name
|
var name = $(this).attr("name");
|
var siteurl = window.location; // 网页连接
|
var title = document.title; // 网页标题
|
|
//点击了收藏一下
|
if (name == 'shoucang')
|
{
|
if (document.all) { window.external.addFavorite(siteurl,title); }
|
else if (window.sidebar) { window.sidebar.addPanel(title, siteurl,''); }
|
else { Showtoast("浏览器不支持,请进行手动添加"); }
|
}
|
//点击了放到桌面
|
else if (name == 'zhuomian')
|
{
|
try
|
{
|
var WshShell = new ActiveXObject("WScript.Shell");
|
var oUrlLink = WshShell.CreateShortcut(WshShell.SpecialFolders("Desktop") + "\\" + title + ".url");
|
oUrlLink.TargetPath = siteurl;
|
oUrlLink.Save();
|
}
|
catch (e) { Showtoast("当前浏览器安全级别不允许操作"); }
|
}
|
});
|
//logo点击
|
$('.titlelogo').click(function(){ window.location.href = 'index.html'; });
|
//-------------------------------------------------------------
|
//移动版按钮悬浮
|
$(".titlephone").mouseover(function() { show_erweima = true; Show_ewm(); });
|
$(".titlephone").mouseout(function() { show_erweima = false; Show_ewm(); });
|
|
//导航栏点击
|
$(".daodan").click(function() { index_dao = $(this).attr("name"); Show_dao(); });
|
//-------------------------------------------------------------
|
//搜索按钮点击
|
$(".searchbtn").click(function()
|
{
|
shuru = $("#ishuru").val();
|
//没有输入内容时
|
if (shuru.length <= 0) { Showtoast("请输入宝贝标题"); }
|
//有输入内容时
|
else { Go_search(); }
|
});
|
$("#ishuru").keyup(function(ev)
|
{
|
if (ev.keyCode == '13')
|
{
|
shuru = $("#ishuru").val();
|
//没有输入内容时
|
if (shuru.length <= 0) { Showtoast("请输入宝贝标题"); }
|
//有输入内容时
|
else { Go_search(); }
|
}
|
});
|
|
|
//输入框输入中
|
$("#ishuru").bind('input propertychange', function() { shuru = $(this).val(); Get_lian(); });
|
//输入框获取焦点
|
$("#ishuru").click(function(ev){ ev.stopPropagation(); show_liandiv = true; Show_lian(); });
|
//输入框失去焦点
|
$(".allwai").click(function(){ show_liandiv = false; Show_lian(); });
|
|
|
|
//======================== 数据请求 ============================
|
//联想关键字
|
function Get_lian ()
|
{
|
var myurl = https + '/fanli/api/web/v1/webSearch/suggestsearch';
|
var mydata = { kw: shuru };
|
AjaxJsonp(myurl, mydata, function(res)
|
{
|
if (res.code != 0) { Showtoast(res.msg); }
|
else { shurulian = res.data; Show_lian(); }
|
});
|
}
|
//进入商品列表页面
|
function Go_search ()
|
{
|
//缓存输入值
|
SetCookie('index_shuru', shuru, 1);
|
//跳转到商品页
|
window.location.href = "search.html";
|
}
|
|
|
|
//======================== 页面数据打印 ============================
|
//导航栏选择项样式
|
Show_dao();
|
function Show_dao () { $(".daodan").eq(index_dao).addClass("daoxuan").siblings().removeClass("daoxuan"); }
|
//显示二维码
|
Show_ewm();
|
function Show_ewm () { if (show_erweima == true) { $(".titleerwm").show(); } else { $(".titleerwm").hide(); } }
|
//打印出联想关键字
|
Show_lian();
|
function Show_lian ()
|
{
|
if (show_liandiv == true && shurulian.length > 0)
|
{
|
//删除所有子元素
|
$(".searchlianwai").empty();
|
//向div中循环添加节点
|
for (var i = 0; i < shurulian.length; i++) { var jiedian = '<div class="searchliandan">'+shurulian[i]+'</div>'; $(".searchlianwai").append(jiedian); }
|
//联想词点击事件
|
$(".searchliandan").click(function()
|
{
|
shuru = $(this).html();
|
$("#ishuru").val(shuru);
|
Go_search();
|
});
|
//显示
|
$(".searchlianwai").show();
|
}
|
else { $(".searchlianwai").hide(); }
|
}
|
|
});
|
|