DedeCMS is a very popular CMS website building system, which is widely favored for its user-friendliness, ease of use, scalability and open source. Among them, the search box style of DedeCMS is an integral part because it is easily noticed by users. However, the default search box style of DedeCMS seems a bit single and outdated, and does not meet the needs of modern websites. So how can we make the search box style of DedeCMS more in line with the needs of modern websites? This article came into being. This article will take DedeCMS 5.7SP2 stable version as an example to explain how to beautify and modify the search box style by modifying JS files.
- Locating JS files
The search function of DedeCMS is implemented in JavaScript, so we need to find the corresponding JS file and modify it. In DedeCMS, commonly used JS files are placed in the "/dede/js" directory. We can find the "search_guide.js" file in this directory. This is the JS file that needs to be modified.
- Backup JS file
Before modifying the JS file, we must first back up the original JS file to avoid errors due to misoperation. After copying the "search_guide.js" file, rename it to "search_guide_backup.js" as a backup file.
- Modify the JS file
After finding the "search_guide.js" file, open the file with a text editor and find the following code at the end of the file:
if($("#query").length>0) //搜索框表单ID { $('#query').bind('focus',function(){ if(this.value=='输入搜索内容') this.value=''; if(this.style.backgroundColor=='#FFF3EA'||this.style.backgroundColor=='rgb(255, 243, 234)') this.style.backgroundColor='#FFFFFF'; }).bind('blur',function(){ if(this.value=='') this.value='输入搜索内容'; if(this.style.backgroundColor=='#FFFFFF'||this.style.backgroundColor=='rgb(255, 255, 255)') this.style.backgroundColor='#FFF3EA'; }); $("#query").keyup(function(e){ if(e.keyCode == 13) { window.location.href = ('/search.php?q='+encodeURIComponent(document.getElementById("query").value)); } }); }
This code implements functions such as automatic clearing, automatic filling, and direct jump of the search box, but does not make any modifications to the style of the search box. We need to modify this code and add corresponding styles to beautify the search box.
The following is our modified code:
if($("#query").length>0) //搜索框表单ID { $('#query').bind('focus',function(){ if(this.value=='输入搜索内容') this.value=''; if(this.style.backgroundColor=='#FFF3EA'||this.style.backgroundColor=='rgb(255, 243, 234)') this.style.backgroundColor='#FFFFFF'; $(this).addClass('search_focus'); }).bind('blur',function(){ if(this.value=='') this.value='输入搜索内容'; if(this.style.backgroundColor=='#FFFFFF'||this.style.backgroundColor=='rgb(255, 255, 255)') this.style.backgroundColor='#FFF3EA'; $(this).removeClass('search_focus'); }); $("#query").keyup(function(e){ if(e.keyCode == 13) { window.location.href = ('/search.php?q='+encodeURIComponent(document.getElementById("query").value)); } }); }
We added the "addClass" and "removeClass" methods to the Bind function to add and remove class names to the search box. This class name We can use CSS to define the style of the search box. We can define two class names, one is the class name without focus, and the other is the class name with focus. The CSS style is as follows:
.search_box { width: 200px; height: 30px; background-color: #FFF3EA; border: none; font-size: 14px; color: #666666; padding-left: 8px; outline: none; -webkit-appearance: none; } .search_focus { background-color: #ffffff; box-shadow: 0px 1px 5px #ccc; }
We define the basic style of the search box in the class name ".search_box", and define the style when the search box gets focus in the class name ".search_focus". In this way, we can modify and beautify the search box style by modifying these styles.
- Save the JS file
After completing the code modification, we need to save the JS file and replace the original file. We can upload the modified "search_guide.js" file to the "/dede/js" directory of the website through the FTP tool and replace the original file.
- Refresh the web page
We need to refresh the web page to make the modified code take effect. Open the website and click the search box. When the search box gains focus, the style of the search box changes, displaying the style defined by the class name ".search_focus". The style of the search box is no longer a single color, but has a more beautified and modern look.
Conclusion:
In this article, we modify the JavaScript file "search_guide.js" of DedeCMS to beautify the search box style. Of course, in addition to modifying JS files, we can also modify and beautify the style of the search box in other ways, such as using CSS style sheets. However, JavaScript is more convenient and powerful in most cases.
We hope this article can help you beautify and modify the search box style of DedeCMS, and make your website more beautiful and modern.
The above is the detailed content of How to beautify and modify the search box style by modifying JS files. For more information, please follow other related articles on the PHP Chinese website!

No,youshouldn'tusemultipleIDsinthesameDOM.1)IDsmustbeuniqueperHTMLspecification,andusingduplicatescancauseinconsistentbrowserbehavior.2)Useclassesforstylingmultipleelements,attributeselectorsfortargetingbyattributes,anddescendantselectorsforstructure

HTML5aimstoenhancewebcapabilities,makingitmoredynamic,interactive,andaccessible.1)Itsupportsmultimediaelementslikeand,eliminatingtheneedforplugins.2)Semanticelementsimproveaccessibilityandcodereadability.3)Featureslikeenablepowerful,responsivewebappl

HTML5aimstoenhancewebdevelopmentanduserexperiencethroughsemanticstructure,multimediaintegration,andperformanceimprovements.1)Semanticelementslike,,,andimprovereadabilityandaccessibility.2)andtagsallowseamlessmultimediaembeddingwithoutplugins.3)Featur

HTML5isnotinherentlyinsecure,butitsfeaturescanleadtosecurityrisksifmisusedorimproperlyimplemented.1)Usethesandboxattributeiniframestocontrolembeddedcontentandpreventvulnerabilitieslikeclickjacking.2)AvoidstoringsensitivedatainWebStorageduetoitsaccess

HTML5aimedtoenhancewebdevelopmentbyintroducingsemanticelements,nativemultimediasupport,improvedformelements,andofflinecapabilities,contrastingwiththelimitationsofHTML4andXHTML.1)Itintroducedsemantictagslike,,,improvingstructureandSEO.2)Nativeaudioand

Using ID selectors is not inherently bad in CSS, but should be used with caution. 1) ID selector is suitable for unique elements or JavaScript hooks. 2) For general styles, class selectors should be used as they are more flexible and maintainable. By balancing the use of ID and class, a more robust and efficient CSS architecture can be implemented.

HTML5'sgoalsin2024focusonrefinementandoptimization,notnewfeatures.1)Enhanceperformanceandefficiencythroughoptimizedrendering.2)Improveaccessibilitywithrefinedattributesandelements.3)Addresssecurityconcerns,particularlyXSS,withwiderCSPadoption.4)Ensur

HTML5aimedtoimprovewebdevelopmentinfourkeyareas:1)Multimediasupport,2)Semanticstructure,3)Formcapabilities,and4)Offlineandstorageoptions.1)HTML5introducedandelements,simplifyingmediaembeddingandenhancinguserexperience.2)Newsemanticelementslikeandimpr


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

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Atom editor mac version download
The most popular open source editor

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
