Home > Web Front-end > JS Tutorial > JQuery modifies the submitted value before form submission [original]_javascript skills

JQuery modifies the submitted value before form submission [original]_javascript skills

WBOY
Release: 2016-05-16 15:05:43
Original
1157 people have browsed it

When I was working on a company project today, I encountered a problem:

We hope to determine whether the user has added keywords unique to this column (such as "tutorial") when searching in the secondary column. Because we are searching the entire site, if no keywords are added, the search results will be It’s a lot and very complicated, so we just want to search for all tutorial-related things under the tutorial column, so we thought a little bit more and made some small changes to the search keywords. The code is as follows:

Copy code The code is as follows:

$('#search-form').submit(function() {
//Get keyword
$keyword = $('#keyword');

//Determine whether the "tutorial" keyword is included
if($keyword.val().indexOf('tutorial') < 0)
{
$keyword.val($keyword.val() + 'tutorial');
}
});

Just use this code. When we search for CSS tutorials, the program will judge that the package does not contain it and will not splice the word "tutorial" into the keyword. When we search for CSS, it will splice it into " Searched for "CSS tutorial".

OK, I hope I can give you some help.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template