JS multiple full selection and cancellation of full selection implementation code _JAVASCRIPT skills

Source: Internet
Author: User
Copy Code code as follows:

$ ("select"). Change (function () {
var n = $ (this). Children (). length;
var obj;
var i = 1;
$ (this). Children (). each (function () {
if (i = = N)
{
Alert ($ (this). text ());
}
i++;
});
});

Combined with the above two methods, I easily get the effect I want, as follows:
Copy Code code as follows:

function SelectAll ()
{
$ ("select"). Children (). each (function () {$ (this). attr ("Selected", "Selected")})
}

Children () and $ (this) are used respectively. attr ("Selected", "Selected")
A JS usage
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<script type= "Text/javascript" >
<!--
function SelectAll ()
{
var Opts=document.getelementbyid ("Courselist");
for (Var i=0;i<opts.length;i++)
{
Opts[i].selected=true;
}
}
-->
</script>
<body>
<select id= "courselist" name= "courselist" multiple= "multiple" size= "style=" "width:230px"; >
<option value= "003" > (003) Consumer behavior and sales psychology </option>
<option value= "004" > (004) Product planning and market promotion </option>
<option value= "005" > (005) Brand positioning and advertising principles </option>
</select>
<input type= "button" onclick= "SelectAll ()" value= "Select All" >
</form>
</body>

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.