JQuery is a method for getting the same level (for example, in the GridView)

Source: Internet
Author: User

Copy codeThe Code is as follows: <asp: GridView ID = "gvreceept" runat = "server" Width = "100%" AutoGenerateColumns = "False" DataKeyNames = "ID" CssClass = "Grid">
<Columns>
<Asp: TemplateField>
<ItemTemplate>
<Input type = "checkbox" id = "chkReceipt" value = '<% # Eval ("ID") %> 'name = "chkreceept"/>
<Input id = "hdCustomerCode" type = "hidden" value = '<% # Eval ("CustomerCode") %>'/>
<Input id = "hdCustomerName" type = "hidden" value = '<% # Eval ("Customer") %>'/>
<Input class = "hdStatus" type = "hidden" value = '<% # Eval ("Department") %>'/>
</ItemTemplate>
</Asp: TemplateField>
</Asp: GridView>

You want to take the value in the hidden field after the selected checkbox, as follows:Copy codeThe Code is as follows: function selectreceept ()
{
Var checknum = 0;
Var customerCode = "";
Var type = "";
Var url = "";
Checknum = $ ("input: checked"). length;
If (checknum> 1)
{
Alert ("only one record can be selected for collection! ");
Return false;
}
Else
{
Alert (checknum );
If (checknum = 1)
{
CustomerCode = $ ("input: checked "). next (). attr ("value"); // you can use the next () method to obtain the value of the next hdCustomerName. next (). next ().
// CustomerName = $ ("input: checked ~ # HdCustomerName "). val (); // the ID of IE will report an error, firefox will not
Type = $ ("input: checked ~. HdStatus "). attr (" value "); // or you can use the class method to obtain the value,
Url = 'prereceiptdeposit. aspx? CustomerCode = '+ customerCode +' & departmentType = '+ type;
}
Else
{
Url = 'prereceiptdeposit. aspx? CustomerCode = '+ ''+' & departmentType = '+ type;
}
Alert (url );
Universalopenwindowandbreak( 640,600, url, 1 );
Return true;
}
}

JQuery -- checkbox select all/cancel allCopy codeThe Code is as follows: <Head>
<Script src = "jquery-1.3.2.min.js" type = "text/javascript"> </script>
</Head>
<Body>
<Input type = "checkbox" name = "chk_list" id = "chk_list_1" value = "1"/> 1 <br/>
<Input type = "checkbox" name = "chk_list" id = "chk_list_2" value = "2"/> 2 <br/>
<Input type = "checkbox" name = "chk_list" id = "chk_list_3" value = "3"/> 3 <br/>
<Input type = "checkbox" name = "chk_list" id = "chk_list_4" value = "4"/> 4 <br/>
<Input type = "checkbox" name = "chk_all" id = "chk_all"/> select all/cancel all
<Script type = "text/javascript">
$ ("# Chk_all"). click (function (){
$ ("Input [name = 'chk _ list']"). attr ("checked", $ (this). attr ("checked "));
});
</Script>
</Body>
</Html>

JQuery. attr gets/Sets object attribute values, such:
$ ("Input [name = 'chk _ list']"). attr ("checked"); // read the status of all objects whose names are 'chk _ List' (whether or not selected)
$ ("Input [name = 'chk _ list']"). attr ("checked", true); // set the checked value of all objects whose names are 'chk _ list' to true.
Another example is:
$ ("# Img_1"). attr ("src", "test.jpg"); // set the value of srcto 'test.jpg 'with the ID of img_1'
$ ("# Img_1"). attr ("src"); // read the src value whose ID is img_1
The following code gets the value of the checkbox selected in the above instance:Copy codeThe Code is as follows: <script type = "text/javascript">
// Obtain all the checkboxes (sets) whose names are 'chk _ list)
Var arrChk = $ ("input [name = 'chk _ list]: checked ");
// Obtain the value of each checkbox through Traversal
For (var I = 0; I <arrChk. length; I ++)
{
Alert (arrChk [I]. value );
}
</Script>

The code for Traversing with $. each () is as follows:Copy codeThe Code is as follows: <script type = "text/javascript">
Var arrChk = $ ("input [name = 'chk _ list']: checked ");
$ (ArrChk). each (function (){
Window. alert (this. value );
});
});
</Script>

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.