jquery traversal and Manipulation table cell element Select,checkbox,radio

Source: Internet
Author: User
Tags trim

jquery Gets the text and value selected by select:
Syntax Explanation:

The code is as follows Copy Code

1. $ ("#select_id"). Change (function () {//code ...}); Adds an event for a select that fires when one of the items is selected
2. Var checktext=$ ("#select_id"). Find ("option:selected"). Text (); Gets the text selected by select
3. Var checkvalue=$ ("#select_id"). Val (); Gets the value of the Select selection
4. Var checkindex=$ ("#select_id"). Get (0). SelectedIndex; Get the index value selected by select
5. Var maxindex=$ ("#select_id option:last"). attr ("index"); Get the maximum index value for select

jquery Sets the Select selected text and value:

Syntax Explanation:

The code is as follows Copy Code
1. $ ("#select_id"). Get (0). selectedindex=1; To set the Select index value of 1
2. $ ("#select_id"). Val (4); Select to set the value of 4 for the Select
3. $ ("#select_id option[text= ' jQuery ']"). attr ("selected", true); Set the text value of select to the item selected for jquery

jquery Add/Remove option items for select:

Syntax Explanation:

  code is as follows copy code
  1. $ ("#select_id"). Append ("<option value= ' value ' >Text</option>"); Append an option (dropdown)
    2. $ ("#select_id") to select. Prepend ("<option value= ' 0 ' > Please select </option > "); Inserts an option (first position) for the Select
    3. $ ("#select_id option:last"). Remove ();//delete maximum index value option in select ( The last one)
    4. $ ("#select_id option[index= ' 0 ']"). Remove ();//delete option (first)
  with index value 0 in select    5. $ ("#select_id option[value= ' 3 ']"). Remove (); Delete option
    5 $ ("#select_id option[text= ' 4 ')" of value= ' 3 in Select. Remove ();//delete text= in Select 4 ' option

jquery Radio value, checkbox value, select Value, Radio selected, CheckBox selected, select selected, and related

The code is as follows Copy Code

Gets the value of a set of radio selected items
var item = $ (' input[@name =items][@checked] '). Val ();
Gets the text of the Select selected item
var item = $ ("select[@name =items] option[@selected]"). Text ();
The second element of the Select Drop-down box is the currently selected value
$ (' #select_id ') [0].selectedindex = 1;
Radio the second element of a radio group is the currently selected value
$ (' input[@name =items] '). Get (1). checked = true;

Get Value:

The code is as follows Copy Code

text box, text area: $ ("#txt"). attr ("value");
Multiple-selection box checkbox:$ ("#checkbox_id"). attr ("value");
Radio Group Radio: $ ("input[@type =radio][@checked]"). Val ();
Dropdown box Select: $ (' #sel '). Val ();

Example 1

The code is as follows Copy Code

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd"
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8"

<title> Home </title>
<link rel= "stylesheet" href= "Css/main.css" >
<script src= "Js/jquery.min.js" ></script>
<script type= "Text/javascript" src= "Js/validator_for_jquery.js" ></script>
<script type= "Text/javascript" >
function Worning (msg) {
Return alert ("calls the custom prompt method worning:" +msg);
}
var Myworn = {
No:function (msg,dom) {
Alert ("Calls the custom prompt method Myworn:" +msg);
},
Yes:function () {

}
};

</script>
<body style= "text-align:left;padding-left:200px;" >
<div>
Download: <a href= "Js/validator_for_jquery.js" >validator_for_jQuery.js</a>
<form id= ' myForm ' modelformxml= ' model.htm ' method= ' get ' >
User name: <input class= ' needvalid ' modelid= ' name ' name= ' username ' ><br>
<span class= "note" >//texttype= "Chinese required" limit= "5-10" worn= "must be in Chinese ' onblur= ' valid (JQuery (this));" External import validation requires server support </span><br><br>
Password: <input texttype= "required" class= ' needvalid ' type= ' password ' onblur= ' valid (JQuery (this)); "limit=" 6-20 "Name=" PSWD "trim=" no "><br>
Web site: <input texttype= "url" name= "url" limit= "5-100" class= ' needvalid ' onblur= ' valid (JQuery (this)); "Worn= ' Myworn: Wrong URL! ' > <br>
Home Tel: <input class= ' needvalid ' modelid= ' homephone ' name= ' HomePhone ' ><br>
Email:<input texttype= "Email" title= "email address" name= "email" onblur= "Valid (JQuery (this));" limit= "5-10" worn= "worning: ' ><br>
Age: <input texttype= "Chinese" name= "The Age" onblur= "valid" (JQuery (this)); "limit=" 2|4|10 "worn=" Regexpmap: ages are unsuitable! ' ><br>
Birthday: <input modelid= "Birthday" class= ' needvalid ' name= ' birth ' "onblur=" valid (JQuery (this)); "Dateformat=" YYYY year mm month DD Day "worn=" alert: Format: yyyy mm month DD Day "><br>
Sex: <span texttype= "Radio Required" class= ' needvalid ' onclick= ' valid ' (JQuery (this)); "Range=" male | female "rangeworn= ' sex cannot be "Male | female" ' ><input name= "Sex" type= "Radio" value= "male" > Male <input name= "Sex" type= "Radio" value= "female" > </span ><br>
Hobbies: <span id= "checkbox" trim= "No" texttype= checkbox "class= ' needvalid ' name=" hobby "limit="! 1 "limitwarn=" "> <input type= "checkbox" value= "basketball" > Basketball <input type= "checkbox" value= "singing" > Singing <input type= "checkbox" value= "Yangge" > Yangge </span><br>
ID: <input modelid= "Idcardno" class= ' needvalid ' texttype= ' Idcard "name=" Idcard "onblur=" Valid (JQuery (this)); " worn= ' alert: Wrong ID number! ' ><br>
Amount: <input texttype= "required number" name= "Amount" class= ' needvalid ' onkeyup= ' valid ' (JQuery (this)); "Regexp=" ^ ([ 1-9][0-9]{0,4}|0) [.]? [0-9] {0,2}$ "worn= ' unit million, please fill in the state of 0-999999.99 between the two decimal places" ' ><br>
Percent:<input texttype= "required" name= "percent" onkeyup= "valid" (JQuery (this)); "Regexp=" ^ ([-]?[ 0-9]{0,11}?) ([.] [0-9] {1,2})? $ "range=" -100 "worn= ' unit%, please fill in the English state-99.99 to 99.99 of the two decimal" ' ><br>
<button onclick= "Return ssh (jQuery (' #myForm '), '. Needvalid ');" > Validation </button>
</form>
</div>
</body>


Example 2

The code is as follows Copy Code

<form

<input modelid= "username" texttype= "Chinese required" title= "username" limit= "5-10" worn= ' alert: Must be Chinese ' limitworn= "Length cannot be less than 5 or more"
    <script type= "Text/javascript"
    function Shh (dom,selector) {
        if (Formvalid (Dom,selector)) {
             alert ("OK");
            return true;
       }else{
             alert ("No");
            return false;
       }
   }
    </script>
</form>

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.