使用说明
function loadOption() { // 获取phone.html页面对应隐藏域中的值 var osList = getArray("oss"); var ptypeList = getArray("ptypes"); var posList = getArray("poss"); var historyList = getArray("historyConditions"); // 创建节点 createNav("os", osList); createNav("ptype", ptypeList); createNav("pos", posList); // 创建查询记录节点 createNav2("history", historyList); // 为节点添加样式 $(".navlist ul li").each(function(i) { $(this).on("click", function() { $(this).addClass("listyle"); $(this).siblings().removeClass("listyle"); }); }); } // ************************************************************* // 获取phone.html数据 function getArray(id) { var array = new Array(parseInt($("#" + id + "Length").val())); var i = 0; $("#" + id + " input").each(function() { array[i] = this.value; i++; }); return array; } // 显示选中条件项 function showSelectedItem() { var selectedItem = ""; $(".nav li").each(function() { if (this.id == 1) { selectedItem = selectedItem + this.innerHTML + " + "; } }); $("#input_msg").val(selectedItem); } // 擦除选中项 function clearSelectedItem(obj) { var ul = $(obj.parentNode); ul.find("li").each(function() { $(this).css({ "background-color" : "#F1F1F1" }); $(this).attr("id", "0"); }); } // 更新数据 function updateData(obj) { var tagPtype = ""; var tagPos = ""; $(".navlist ul").eq(1).html("");// ptype行清空 $(".navlist ul").eq(2).html("");// pos行清空 $(".more").remove(); if (obj.innerHTML == "ios") { tagPtype = "#ptypesIos input"; tagPos = "#possIos input"; } if (obj.innerHTML == "android") { tagPtype = "#ptypesAndroid input"; tagPos = "#possAndroid input"; } if (obj.innerHTML == "All") { tagPtype = "#ptypes input"; tagPos = "#poss input"; } var ptypeAll_li = $("
").text("All").click(function() {
clearSelectedItem(this);
showSelectedItem();
});
ptypeAll_li.appendTo($(".navlist ul").eq(1));
var count = 0;
$(tagPtype).each(function() {
count++;
var navli = $("
").text(this.value).click(function() {
clearSelectedItem(this);
$(this).attr("id", "1");
var value = this.innerHTML;
showSelectedItem();
// 根据ptype动态更新pos
if (this.value != "All") {
findPosByPtype(this.innerHTML);
}
});
navli.appendTo($(".navlist ul").eq(1));
});
if (count > 3) {
var amore = $("
").addClass("more").attr("href", "#").attr("id", "ptype_id").click(function() { showMoreItem("ptype", 30); }); var span3 = $(" ").text("more"); var span4 = $(" ").addClass( "glyphicon glyphicon-triangle-bottom").attr("aria-hidden", "true"); $(span3).appendTo(amore); $(span4).appendTo(amore); $(amore).appendTo($(".innav").eq(1)); } var posAll_li = $(" ").text("All").click(function() { clearSelectedItem(this); showSelectedItem(); }); posAll_li.appendTo($(".navlist ul").eq(2)); var count2 = 0; $(tagPos).each(function() { count2++; var navli = $("
").text(this.value).click(function() { clearSelectedItem(this); $(this).attr("id", "1"); var value = this.innerHTML; showSelectedItem(); }); navli.appendTo($(".navlist ul").eq(2)); }); if (count2 > 3) { var amore = $(" ").addClass("more").attr("href", "#").attr("id", "pos_id").click(function() { showMoreItem("pos", 30); }); var span3 = $(" ").text("more"); var span4 = $(" ").addClass( "glyphicon glyphicon-triangle-bottom").attr("aria-hidden", "true"); $(span3).appendTo(amore); $(span4).appendTo(amore); $(amore).appendTo($(".innav").eq(2)); } $(".navlist ul li").each(function(i) { $(this).on("click", function() { $(this).addClass("listyle"); $(this).siblings().removeClass("listyle"); }); }); } // 查询记录 function history(condition) { $(".navlist ul").eq(3).html(condition); } // 删除节点 function deleteNode(id) { var id = id.substring(0, (id.length - 1)); var condition = $("#" + id).val(); $.ajax({ async : false, type : "POST", url : "deleteHistory.do", data : { "condition" : condition }, success : function(data) { $("#input_msg").val(""); $("#history_condition").val(""); $("#option_select").empty(); loadOption(); findHistoryAll(); } }); } // 查询搜索历史 function findHistoryAll() { $ .ajax({ async : false, type : "POST", url : "findHistory.do", success : function(jsonArray) { var length = eval(jsonArray).length; var historyHidden = $("#historyConditions"); $("#historyConditionsLength").val(length); $(historyHidden).empty(); $(".navlist ul").eq(3).html(""); $("#history_id").remove(); // 在页面上存放数据 for (var i = 0; i < length; i++) { var input = ""; if(eval(jsonArray)[i].code != ""){ input = $(" "); }else{ input = $(" "); } $(input).appendTo($(historyHidden)); } // 显示搜索数据 var i = 0; // 计数器 $("#historyConditions input") .each( function() { var item_btn = $( " search" + (i + 1) + " ")
.click(
function() {
clearSelectedItem(this.parentNode);
$(
"#history_condition")
.val(
$(
"#"
+ this.innerHTML)
.val());
searchByCondition(1);
});
$(item_btn) .addClass("tooltip-test") .attr("data-toggle", "tooltip") .attr("id","heidt"+i) .attr( "title", $( "#search" + (i + 1) + "") .val()); var delete_btn = $( " ") .attr( "id", "search" + (i + 1) + "z") .click(function() { deleteNode(this.id); }); var edit_btn = $( " ") /*.attr( "id", "search" + (i + 1) + "z")*/.click(function() { //alert(1); var aTxt = $(this).parent().text(); var ahtml = $(this).siblings("a").text(); $(this).siblings("a").html(" "); $("#content").focus().select(); $("#content").blur(function(){ var nhtml = $("#content").val(); $(this).parent().html(nhtml); }); }); var navli = $("
");
$(item_btn).appendTo(navli);
$(delete_btn).css("float", "right");
$(edit_btn).css({"float": "right","margin-top":"-1px"});
$(delete_btn).appendTo(navli);
$(edit_btn).appendTo(navli);
$(navli).appendTo(
$(".navlist ul").eq(3));
i++;
});
if(i>4){
var amore = $("
").addClass("more").attr("href", "#").attr("id","history_id").click(function() { showMoreItem("history", 30); }); var span3 = $(" ").text("more"); var span4 = $(" ").addClass( "glyphicon glyphicon-triangle-bottom").attr("aria-hidden", "true"); $(span3).appendTo(amore); $(span4).appendTo(amore); $(amore).appendTo($(".innav").eq(3)); } } }); } // ****************************************************************** // 创建os和ptype节点 function createNav(text, num) { var navdiv = $("
").addClass("innav"); var headerdiv = $("
").addClass("navheader"); var listdiv = $("
").addClass("navlist"); var span1 = $(" ").text(text); var span2 = $(" ") .addClass("glyphicon glyphicon-chevron-right").attr("aria-hidden", "true"); var navul = $(""); var navli_All = $(" ").text("All").click(function() { // 清除所有ptype标记 clearSelectedItem(this); updateData(this); // 清除input中的值 $("#input_msg").val(""); // searchByCondition(1); }); if (text == "os") { $(navli_All).addClass("listyle"); } if (text == "os" || text == "ptype" || text == "pos") { $(navli_All).appendTo(navul); } $(span1).appendTo(headerdiv); $(span2).appendTo(headerdiv); $(headerdiv).appendTo(navdiv); for (var i = 0; i < num.length; i++) { var navli = $("
").text(num[i]).click( function() { $(this).addClass("lilistyle"); $(this).siblings().removeClass("lilistyle"); // 清除第一个All选项选中状态 // 清除所有ptype标记 clearSelectedItem(this); // 为当前项设置标记 $(this).attr("id", "1"); var value = this.innerHTML; if (value == "ios") { updateData(this); } if (value == "android") { updateData(this); } // 正则匹配pos,过滤掉 var regex = /^(\d\.?)+$/; // 根据ptype动态更新pos if (value != "ios" && value != "android" && value != "All" && !regex.test(value)) { findPosByPtype(value); } showSelectedItem(); }); $(navli).appendTo(navul); } $(navul).appendTo(listdiv); $(listdiv).appendTo(navdiv); $(navdiv).appendTo(".nav"); var a = parseInt(num.length / 6 + 1); $(navul).height(a * 30); var ulheight = $(navul).height(); if (num.length > 3 && (text == "ptype" || text == "pos")) { var type = text; var amore = $(" ").addClass("more").attr("href", "#").attr("id", type + "_id").click(function() { showMoreItem(type, ulheight); }); var span3 = $(" ").text("more"); var span4 = $(" ").addClass( "glyphicon glyphicon-triangle-bottom").attr("aria-hidden", "true"); $(span3).appendTo(amore); $(span4).appendTo(amore); $(amore).appendTo(navdiv); } } function showMoreItem(text, ulheight) { var navheight = 0; var innav = null; if (text == "ptype") { navheight = $(".innav:eq(1)").height(); innav = $(".innav:eq(1)"); } if (text == "pos") { navheight = $(".innav:eq(2)").height(); innav = $(".innav:eq(2)"); } if (text == "history") { navheight = $(".innav:eq(3)").height(); innav = $(".innav:eq(3)"); } if (navheight == 30) { innav.animate({ height : ulheight + 32 }, 100); // $(".nav").animate({height :ulheight+90},100); } else { innav.animate({ height : navheight - 32 }, 100); // $(".nav").animate({height : navheight}, 100); } } // 创建history节点 function createNav2(text, num){ var navdiv = $("
").addClass("innav"); var headerdiv = $("
").addClass("navheader"); var listdiv = $("
").addClass("navlist"); var span1 = $(" ").text(text); var span2 = $(" ") .addClass("glyphicon glyphicon-chevron-right").attr("aria-hidden", "true"); var navul = $(""); $(span1).appendTo(headerdiv); $(span2).appendTo(headerdiv); $(headerdiv).appendTo(navdiv); for (vari = 0; i < num.length; i++) { var item_btn = $("search" + (i + 1) + " ").click( function() { clearSelectedItem(this.parentNode); $("#history_condition").val($("#" + this.innerHTML).val()); searchByCondition(1); }); $(item_btn).addClass("tooltip-test").attr("data-toggle", "tooltip").attr("id","heidt"+i) .attr("title", $("#search" + (i + 1) + "").val()); var delete_btn = $( " ") .attr("id", "search" + (i + 1) + "z").click(function() { deleteNode(this.id); }); var edit_btn = $( " ") /*.attr( "id", "search" + (i + 1) + "z")*/.click(function() { var aTxt = $(this).parent().text(); var ahtml = $(this).siblings("a").text(); $(this).siblings("a").html(" "); $("#content").css({ "width":"50px", "height":"16px", "outline":"none", "-webkit-appearance":"none" }); $("#content").focus().select(); $("#content").blur(function(){ var nhtml = $("#content").val(); $(this).parent().html(nhtml); //bug code!=null var code = nhtml; var conditiona = $("#"+aTxt).val(); saveSearch(code,conditiona); }); }); var navli = $("
"); $(delete_btn).css("float", "right"); $(edit_btn).css({"float": "right","margin-top":"-1px"}); $(delete_btn).appendTo(navli); $(edit_btn).appendTo(navli); $(item_btn).appendTo(navli); $(navli).appendTo(navul); } $(navul).appendTo(listdiv); $(listdiv).appendTo(navdiv); $(navdiv).appendTo(".nav"); var a = parseInt(num.length / 7 + 1); $(navul).height(a * 30); var ulheight = $(navul).height(); if (num.length > 4) { var amore = $(" ").addClass("more").attr("href", "#").attr("id","history_id").click(function() { showMoreItem("history", ulheight); }); var span3 = $(" ").text("more"); var span4 = $(" ").addClass( "glyphicon glyphicon-triangle-bottom").attr("aria-hidden", "true"); $(span3).appendTo(amore); $(span4).appendTo(amore); $(amore).appendTo(navdiv); } } function saveSearch(code,condition){ $.ajax({ async : false, type : "POST", url : "saveSearchCondition.do", data : { "condition" : condition, "code":code }, success : function(data) { alert("ok"); } }); }; // ******************************************************** function findPosByPtype(ptype) { $(".navlist ul").eq(2).html(""); // pos行清空 $("#pos_id").remove(); var value = ""; $("#posToPtype input").each(function() { if (this.id == ptype) { value = this.value; } }); var posList = value.split(","); var posAll_li = $("
").text("All").click(function() { clearSelectedItem(this); showSelectedItem(); }); posAll_li.appendTo($(".navlist ul").eq(2)); for (var i = 0; i < posList.length; i++) { var navli = $(" ").text(posList[i]).click(function() { clearSelectedItem(this); $(this).attr("id", "1"); var value = this.innerHTML; showSelectedItem(); }); navli.appendTo($(".navlist ul").eq(2)); } if (posList.length > 3) { var amore = $(" ").addClass("more").attr("href", "#").attr("id", "pos_id").click(function() { showMoreItem("pos", 30); }); var span3 = $(" ").text("more"); var span4 = $(" ").addClass( "glyphicon glyphicon-triangle-bottom").attr("aria-hidden", "true"); $(span3).appendTo(amore); $(span4).appendTo(amore); $(amore).appendTo($(".innav").eq(2)); } $(".navlist ul li").each(function(i) { $(this).on("click", function() { $(this).addClass("listyle"); $(this).siblings().removeClass("listyle"); }); }); }