


Implementing advanced search functions similar to Baidu Academic based on JavaScript_javascript skills
Baidu Academichttp://xueshu.baidu.com/Advanced retrieval is achieved through the front-end generating internal advanced grammar in the back-end. It can be implemented through string splicing in the front-end js and passed to the back-end. Not too difficult:
The following is the core function code of advanced search. I use pure js implementation and do not use jquery:
<p class="fl srh-btn"> <input type="submit" class="srh-submit" style="height:px" value="高级搜索" id="highSearchObj"/> </p> //省略部分调用关系 this.highSearch = function () { document.getElementById('highSearchObj').disabled=true; var highSearchHtml = '<div class="highSearch" style="display:block"><div class="highMsg"><ul> \ <li><span id="tabReg" class="tab">包含关键词</span><input id="kywds" value=""></li> \ <li><span id="tabReg" class="tab">不包含关键词</span><input id="nokywds" value=""></li>\ <li><span id="tabReg" class="tab">检索范围</span>\ <select id="st">\ <option value ="byrw">本院认为</option>\ <option value ="sljg">审理经过</option>\ <option value="ygsc">原告诉称</option>\ <option value="bgbc">被告辩称</option>\ </select></li>\ </ul>\ <input id="conditionObj" type="submit" value="新增一组条件"></input>\ <hr>\ <div class="fit">\ <select id="type">\ <option value ="all">全部</option>\ <option value ="pj">判决</option>\ <option value ="cd">裁定</option>\ <option value="tz">通知</option>\ <option value="jd">决定</option>\ <option value="tj">调解</option>\ </select><select id="round">\ <option value ="all">全部</option>\ <option value ="one">一审</option>\ <option value ="two">二审</option>\ <option value="again">再审</option>\ </select>\ <input id="bg" value="">-<input id="end" value="">\ <ul><li><span id="tabReg" class="tab">案由</span><input id="ay" value=""></input></li>\ <li><span id="tabReg" class="tab">法院</span><input id="fy" value=""></input></li>\ </ul></div>\ <ul id="sql"></ul>\ <input id="submitHighSearchObj" type="submit" value="提交高级搜索"></input>\ </div></div>'; this.highSearchObj = $(highSearchHtml); $("body").append(this.highSearchObj); $("#conditionObj").click(function(){ var kywds="\""+document.getElementById("kywds").value.split(" ").join("\"&\"")+"\""; var st=document.getElementById("st").value; var nokywds="\""+document.getElementById("nokywds").value.split(" ").join("\"|\"")+"\""; var sql="<li name=\"highTag\">@("+st+")("+kywds+"-"+nokywds+")</li>"; $("#sql").append(sql); }) $("#submitHighSearchObj").click(function(){ var highTags=document.getElementsByName("highTag"); var tags=""; var filters=""; var round=document.getElementById("round").value; var type=document.getElementById("type").value; var reason=document.getElementById("ay").value.split(" ").join(","); var court=document.getElementById("fy").value.split(" ").join(","); var begin=document.getElementById("bg").value; var end=document.getElementById("end").value; if(highTags.length==){ var kywds="\""+document.getElementById("kywds").value.split(" ").join("\"&\"")+"\""; var st=document.getElementById("st").value; var nokywds="\""+document.getElementById("nokywds").value.split(" ").join("\"|\"")+"\""; tags="@("+st+")("+kywds+"-"+nokywds+")"; } else { for(i=;i<highTags.length;i++){ tags+=highTags[i].innerHTML; } } if(round !="all") { filters+=" round:"+round+";"; } if(type !="all") { filters+=" type:"+type+";"; } if(reason !="") { filters+=" reason:"+reason+";"; } if(court !="") { filters+=" court:"+court+";"; } if(begin !="" && end !="") { filters+=" year:"; while(begin<=end) { filters=filters+begin+","; begin++; } } if(filters !="") { tags="magic:"+tags+";filter:"+filters; } var formObj = $('<form id="form" action="/search" target="_self" method="get"></form>'); var html = ['<input type="hidden" name="type" value="">']; html.push('<input type="hidden" name="keyword" value="' + encodeURIComponent(tags) + '">'); html.push('<input type="hidden" name="TypeKey" value="' + encodeURIComponent(tags) +'">'); formObj.html(html.join(",")); $("body").append(formObj); formObj.submit(); }); // $("#ay").keyup(function(e){ // }); }
Lines 3 to 36 are mainly the HTML code of the pop-up window.
Lines 37 and 38 use the simplest method commonly used in js to dynamically modify the frontend in the page.
Lines 39 and 46 are both action processing of the new code, used to submit conditions and sub-conditions.
In the function on line 46, string splicing is done.
In lines 88 to 96, the js+html call for submitting query conditions through a hidden form is implemented.
jquery js implements search condition switching in advanced conditional search function
Basic idea:
1.HTML:
Use table to display all search conditions, use input control to display each search condition, and define two CSS class styles to distinguish the selected and unselected status of the search conditions
2.JS implementation:
Binding click events for unselected inputs can be achieved by binding unselected style classes, code implementation
function (event) {//event为点击事件 $(event.target).parent().find( '.条件input-selected' ).toggleClass('条件input-selected' ).toggleClass( '条件input-default'); $(event.target).toggleClass( '条件input-selected' ).toggleClass('条件input-default' ); },
At this point, automatic switching of all search conditions is achieved

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

How to merge array elements with the same ID into one object in JavaScript? When processing data, we often encounter the need to have the same ID...

Learning JavaScript is not difficult, but it is challenging. 1) Understand basic concepts such as variables, data types, functions, etc. 2) Master asynchronous programming and implement it through event loops. 3) Use DOM operations and Promise to handle asynchronous requests. 4) Avoid common mistakes and use debugging techniques. 5) Optimize performance and follow best practices.

Discussion on the realization of parallax scrolling and element animation effects in this article will explore how to achieve similar to Shiseido official website (https://www.shiseido.co.jp/sb/wonderland/)...

In-depth discussion of the root causes of the difference in console.log output. This article will analyze the differences in the output results of console.log function in a piece of code and explain the reasons behind it. �...

Explore the implementation of panel drag and drop adjustment function similar to VSCode in the front-end. In front-end development, how to implement VSCode similar to VSCode...
