Jquery $ application note (continuously updated)

Source: Internet
Author: User

Javascript

Jquery

Register an event

   

<Asp: button id = "button" text ="Button"Runat =" server"

Onclientclick = "javascript: clickevent ();"/>

$ ("# <% = Button. clientid %> ").Click(Isclick );

$ ("# <% = Button. clientid %> ").Blur(Isblur );

Or

$ ("# <% = Button. clientid %> ").Blur(Function (){

Isblur ();

});

   

Get controlID

   

Document. getelementbyid ('trremark ')

$ ("# Trremark ")

Get server controlsID

   

Document. getelementbyid ('<% = button. clientid %> ')

$ ("# <% = Button. clientid %> ")

display and hide htmlelements

document. getelementbyid ("TR "). style ("display", "inline");

document. getelementbyid ("TR "). style ("display", "NONE");

$ (" # TR "). show ();

$ (" # TR "). hide ();

$ (" # TR "). toggle ();

Get value\Text

   

Document. getelementbyid ("TXT"). Value

Document. getelementbyid ("TXT"). innertext

   

$ ("# <% = TXT. clientid %>"). Val ()

$ ("# <% = TXT. clientid %>"). Text ()

$ ("# <% = Dropdownlist. clientid %> Option: Selected"). Text ()

Array

   

var arr = new array ();

arr [0] =" ";

arr [1] = B;

arr [2] =" C ";

var arr = [" A ", B," C "];

JudgmentArrayIs thereFalse

   

For(VAR I =0; I <entryarray. length; I ++ ){

If (entryarray [I] == false ) {

Flag =False;

Break;

}

}

If(Flag =False){

// Todo

}

   

If ($. inarray ("false", entryarray )! =-1 ){

// Todo

}

   

Determine whether the object isUndefined

   

Typeof (document. getelementbyid ('trremark '))! = "Undefined"

Typeof trremark! = 'Undefined'

Load Style

   

   

$ ("# <% = Button. clientid %>" ).css ("bordercolor", "Red ");

Assign values to elements

   

Document. getelementbyid ("textbox"). value = "1234 ";

$ ("# Textbox"). Val ("1234 ");

Indexof

   

JSInclusion relationship

UseIndexof ()Method

If> = 0Otherwise, it does not contain

VaR A = "testhelloword ";

Document. Write (A. indexof ("hello "));

   

$ ("# Textbox"). Val (). indexof ("Hello") <0

It is found that the add () of the encapsulated element set is good.
Solve one of my earlier questions:
$ ("# <% = Button1.clientid %>"). Click (clickevent );
$ ("# <% = Button2.clientid %>"). Click (clickevent );
$ ("# <% = Button3.clientid %>"). Click (clickevent );
The events of the above three buttons are the same.
I don't write it like this every time. How can we simplify it?
Use add ()
$ ("# <% = Button1.clientid %> ")
. Add ("# <% = button2.clientid %> ")
. Add ("# <% = button3.clientid %> ")
. Click (clickevent );

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.