jquery set up and get HTML, text, and values

Source: Internet
Author: User
Tags cdata

jquery set and get HTML, text, and values press Ctrl+C Copy Code<script type= "Text/javascript" >//<! [Cdata[$(function(){      //get the HTML code for the <p> element$ ("Input:eq (0)"). Click (function() {alert ($ ("P"). HTML ());      }); //gets the text of the <p> element$ ("Input:eq (1)"). Click (function() {alert ($ ("P"). text ());      }); //HTML code for settings <p> elements$ ("Input:eq (2)"). Click (function(){             $("P"). HTML ("<strong> your favorite fruit is?</strong>");           }); //set the text of the <p> element$ ("Input:eq (3)"). Click (function(){             $("P"). Text ("What's your favorite fruit?").);        }); //set the text of the <p> element$ ("Input:eq (4)"). Click (function(){             $("P"). Text ("<strong> your favorite fruit is?</strong>");        }); //gets the value of the button$ ("Input:eq (5)"). Click (function() {alert ($ ( This). Val ());         }); //set the value of the button$ ("Input:eq (6)"). Click (function(){            $( This). val ("I've been clicked!"));    });  }); //]]></script> Press CTRL +C Copy Code<script type= "Text/javascript" >//<! [Cdata[$(function(){      $("#address"). Focus (function(){//Address box get mouse focus            varTxt_value = $ ( This). Val ();//get the value of the current text box            if(txt_value== "Please enter your email address"){                  $( This). Val ("");//empty the contents of the text box if the condition is met            }       }); $("#address"). Blur (function(){//Address box loses mouse focus              varTxt_value = $ ( This). Val ();//get the value of the current text box            if(txt_value== ""){                $( This). val ("Please enter your email address");//If the condition is met, the content is set            }       })      $("#password"). Focus (function(){            varTxt_value = $ ( This). Val (); if(txt_value== "Please enter your email password"){                $( This). Val ("");      }       }); $("#password"). Blur (function(){              varTxt_value = $ ( This). Val (); if(txt_value== ""){                $( This). val ("Please enter your email password"));  }       })  }); //]]></script> <script type= "Text/javascript" >//<! [Cdata[$(function(){      $("#address"). Focus (function(){//Address box get mouse focus            varTxt_value = $ ( This). Val ();//get the value of the current text box            if(txt_value== This. DefaultValue) {                  $( This). Val ("");//empty the contents of the text box if the condition is met            }       }); $("#address"). Blur (function(){//Address box loses mouse focus              varTxt_value = $ ( This). Val ();//get the value of the current text box            if(txt_value== ""){                $( This). Val ( This. DefaultValue);//If the condition is met, the content is set            }       })      $("#password"). Focus (function(){            varTxt_value = $ ( This). Val (); if(txt_value== This. DefaultValue) {                $( This). Val ("");      }       }); $("#password"). Blur (function(){              varTxt_value = $ ( This). Val (); if(txt_value== ""){                $( This). Val ( This. DefaultValue);  }       })  }); //]]></script> <script type= "Text/javascript" >//<! [Cdata[$(function(){      //set the single-selection drop-down box to select$ ("Input:eq (0)"). Click (function(){            $("#single"). Val ("2"));      }); //set the multi-select drop-down box to select$ ("Input:eq (1)"). Click (function(){            $("#multiple"). val (["Select 2nd", "select Number 3rd")]);      }); //Set the Radio box and the Multi marquee check box$ ("Input:eq (2)"). Click (function(){             $(": CheckBox"). Val (["Check2", "Check3"]); $(": Radio"). Val (["Radio2").]);      });  }); //]]></script> <script type= "Text/javascript" >//<! [Cdata[$(function(){      //set the single-selection drop-down box to select$ ("Input:eq (0)"). Click (function(){            $("#single option"). Removeattr ("selected");//Remove Attribute selected$ ("#single option:eq (1)"). attr ("Selected",true);//Set Property selected      }); //set the multi-select drop-down box to select$ ("Input:eq (1)"). Click (function(){            $("#multiple option"). Removeattr ("selected");//Remove Attribute selected$ ("#multiple Option:eq (2)"). attr ("Selected",true);//Set Property selected$ ("#multiple Option:eq (3)"). attr ("Selected",true);//Set Property selected      }); //Set the Radio box and the Multi marquee check box$ ("Input:eq (2)"). Click (function(){            $(": CheckBox"). Removeattr ("checked");//Remove attribute checked$ (": Radio"). Removeattr ("checked");//Remove attribute checked$ (": Checkbox[value=check2]"). attr ("Checked",true);//Set Property Checked$ ("[Value=check3]:checkbox"). attr ("Checked",true);//Set Property Checked$ ("[Value=radio2]:radio"). attr ("Checked",true);//Set Property Checked      });  }); //]]></script>: checkbox indicates that the property is a checkbox

jquery set up and get HTML, text, and values

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.