Use jQuery to remove tags and remove duplicates. jquerytag

Source: Internet
Author: User

Use jQuery to remove tags and remove duplicates. jquerytag

Let's just look at the code.

Core code of the jsp page


<Head>

<Script type = "text/javascript" src = "js/jQuery. js"> </script> // jquery reference code

<Script type = "text/javascript" src = "js/delRepeat. js"> </script> // deduplicated js Code

</Head>

<Body>

<Input id = "repeatValue" type = "text" onblur = "delRepeat ()">

</Body>


DelRepeat. js

Function delRepeat (){
Var str = $ ('# repeatvalue'). val ();
Var strArr = str. split (""); // splits the string into an array by space.


Var uniqueArr = [];
$. Each (strArr, function (I, el ){
If ($. inArray (el, uniqueArr) ===-1) uniqueArr. push (el );
});
$ ('# Repeatvalue'). val (uniqueArr. join (""); // combine strings

}

Done!


Teach jquery: remove duplicates when adding drop-down menu options

Jquery's $. unique method is used to remove array duplicates. Here is a small example. How can we combine it with your instance?
Var arr = ['ason ', 'dremo', 'pobbe', 'eason'];
$. Unique (arr );
Alert (arr. join (","));

Jquery question: why does this website http: // www5icoolorg/tagphp? Tag = on the Right of jQuery, how does this effect be shared?

No, but I want to share it.
References: Fan
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.