Implementation Code for getting form elements through filters in jquery

Source: Internet
Author: User

: Enable to obtain the elements in the input state
: Disabled: gets elements that cannot be entered.
: Checked: Get the selected form Element
: Seleced: Obtain the selected element from the drop-down list.
The following is an example.
Html Copy codeThe Code is as follows: <body>
<Form id = "form1" runat = "server">
<Div>
<Ul>
<Li> <label> Order Number: </label> <input type = "text" disabled = "disabled"/> </li>
<Li> <label> order owner: </label> <input type = "text"/> </li>
<Li>
<Input type = "checkbox" name = "ca" value = "red"/> Red
<Input type = "checkbox" name = "ca" value = "yellow"/> yellow
<Input type = "checkbox" name = "ca" value = "blue"/> blue
<Input type = "checkbox" name = "ca" value = "green"/> green
</Li>
<Li>
<Select multiple = "multiple">
<Option> select 1 </option>
<Option> select 2 </option>
<Option> select 3 </option>
<Option> select 4 </option>
</Select>
</Li>
</Ul>
</Div>
</Form> <div id = "msg">
<P id = "cc"> </p>
<P id = "option"> </p> </div>
</Body>

JavaScript code:Copy codeThe Code is as follows: <script type = "text/javascript">
JQuery (function (){
$ ("Input: text: disabled"). val ("cannot input ");
$ ("Input: text: enabled"). val ("can be entered ");
(
Function checkboxclick (){
$ (": Checkbox"). unbind ("click", checkboxclick );
Var vv = '';
$ (": Checkbox: checked"). each (function (){
Vv + = $ (this). val () + ",";
});
$ ("# Cc" ).html ("selected data:" + vv );
$ (": Checkbox"). click (checkboxclick );
}
)()
$ ("Select"). change (function (){
Var tt = '';
$ ("Select option: selected"). each (function (){
Tt + = $ (this). text () + ",";
});
$ ("# Option" pai.html ("the selected project is:" + tt );
}). Trigger ("change ");
});
</Script>

Note the following points:
1 Previously we mentioned that bind is used to bind events, so the unbind here cancels the event.
2. trigger () method triggers the specified event type of the selected element.
3 when adding a function in jQuery (function () {, brackets should be added to the outside, and parentheses should be added to the end, as shown below:
JQuery (function (){
(
Function check ()
{
})()
})
4. Select the check box in the Implementation Layer and assign it to other element values.
HtmlCopy codeThe Code is as follows: <form id = "form1" runat = "server">
<Div>
<Input type = "button" id = "btn1" value = "pop-up"/>
<Input type = "checkbox" name = "ca" value = "red"/> Red
<Input type = "checkbox" name = "ca" value = "yellow"/> yellow
<Input type = "checkbox" name = "ca" value = "blue"/> blue
<Input type = "checkbox" name = "ca" value = "green"/> green
<Input type = "checkbox" name = "ca" value = "white"/> White
<Input type = "checkbox" name = "ca" value = ""/> black
</Div>
<Div id = "cc"> </div>
</Form>

JavascriptCopy codeThe Code is as follows: jQuery (function (){
(
Function checkboxclick (){
$ (": Checkbox"). unbind ("click", checkboxclick );
Var vv = '';
$ (": Checkbox: checked"). each (function (){
Vv + = $ (this). val () + ",";
})
$ ("# Cc" ).html ("selected data:" + vv );
$ (": Checkbox"). click (checkboxclick );
})()
})

As follows:

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.