Jquery uses bit-by-bit Function Code

Source: Internet
Author: User

1. Simple button js events are used to determine and display prompts
Copy codeThe Code is as follows:
<Script type = "text/javascript" language = "javascript">
$ (Document). ready (function (){
$ ("# Btnlogin"). click (function (){
$ ("# LblInfo" ).html ("");
Var uid = $. trim ($ ("# txtUsername"). val ());
Var pwd = $. trim ($ ("# txtPassword"). val ());
If (uid = ""){
$ ("# LblInfo" ).html ("the account cannot be blank ");
$ ("# TxtUsername"). focus ();
Return false;
}
If (pwd = ""){
$ ("# LblInfo" ).html ("the password cannot be blank ");
$ ("# TxtPassword"). focus ();
Return false;
}
});
});
</Script>


2. process the drop-down list
Copy codeThe Code is as follows:
Function dropTypeChange ()
{
Var sel = $ ("# <% = dropType. ClientID %> option: selected"). val ();
If (sel = "-1 ")
{
$ ("# <% = TxtNo. ClientID %>"). attr ('Disabled ', true );
}
Else
{
$ ("# <% = TxtNo. ClientID %>"). attr ('Disabled ', false );
}
}


// Obtain the value of the first option
$ ('# Test option: first'). val ();
// The value of the last option
$ ('# Test option: last'). val ();
// Obtain the value of the second option
$ ('# Test option: eq (1)'). val ();
// Obtain the selected value
$ ('# Test'). val ();
$ ('# Test option: selected'). val ();
// Option with the value of 2 is selected
$ ('# Test'). attr ('value', '2 ');
// Set the first option to selected
$ ('# Test option: last'). attr ('selected', 'selected ');
$ ("# Test"). attr ('value', $ ('# test option: la'). val ());
$ ("# Test "). attr ('value', $ ('# test option '). eq ($ ('# test option '). length-1 ). val ());
// Obtain the select Length
$ ('# Test option'). length;
// Add an option
$ ("# Test"). append ("<option value = '9'> ff </option> ");
$ ("<Option value = '9'> ff </option>"). appendTo ("# test ");
// Add the selected item
$ ('# Test option: selected'). remove ();
// Select a specified item
$ ('# Test option: first'). remove ();
// The specified value is deleted.
$ ('# Test option'). each (function (){
If ($ (this). val () = '5 '){
$ (This). remove ();
}
});
$ ('# Test option [value = 5]'). remove ();
// Obtain the label of the first Group
$ ('# Test optgroup: eq (0)'). attr ('label ');
// Obtain the value of the first option in the second group
$ ('# Test optgroup: eq (1): option: eq (0)'). val ();

Related Article

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.