Example 1: dynamically setting the src attribute of img. Other dom elements are the same.
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = ISO-8859-1">
<Script type = "text/javascript" src = "js/jquery. js"> </script>
<Script type = "text/javascript">
$ (Document). ready (
Function (){
$ ("# Load"). click (function (){
$ ("Img"). attr ("src", "admin.png"); // set the src attribute of img
$ ("Img"). attr ("src"); // return the src attribute of all img ....
}
);
$ ("# Unload"). click (function (){
$ ("Img"). removeAttr ("src"); // Delete the src attribute of img //
});
}
);
</Script>
<Title> Insert title here </title>
</Head>
<Body>
<Button id = "load"> display </button>
<Button id = "unload"> Delete </button>
</Body>
</Html>
2. Differences in the use of html text val ......
Setting ('p'0000.html (); setting ("<a> xxx <a>"); Setting the html content under p corresponds to the innerHTML attribute of dom $ ('P '). text (); set or obtain the text above .. all text under the p tag... or set .... <a> dxx </a> in this column is parsed into text $ ("p "). text ("Hello world! "); $ (" Input "). val (); get or set the value of the form element .. specific filtering can be combined .. the selector selects our element and then obtains or sets the value $ ("input "). val ("hello world! "); 3. Set css attributes by dynamically setting the class of the dom element <Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = ISO-8859-1">
<Script type = "text/javascript" src = "js/jquery. js"> </script>
<Script type = "text/javascript"> www.2cto.com
$ (Document). ready (
Function (){
$ ("# Load"). click (function (){
$ ("P"). addClass ("styleme"); // Add the class attribute styleme
}
); $ ("# Unload"). click (function (){
$ ("P"). removeClass ("styleme"); // uninstall css attributes
});
}
);
</Script>
<Style type = "text/css">
. Styleme {
Font-size: 20px;
Color: blue;
}
</Style>
<Title> Insert title here </title>
</Head>
<Body>
<P> 23232d </p>
<Button id = "load"> display </button> <button id = "unload"> unmount </button>
</Body>
</Html> $ ("p "). toggleClass ("selected"); // indicates adding a class if it does not exist. 4. Set/obtain the attribute value of the first element in the matched element set. $ ("Input [type = 'checkbox']"). prop ("checked"); get the checked attribute value of the first element in the type = checkbox element set in the input element $ ("input [type = 'checkbox']"). prop ("disabled", false); Disable checkbox $ ("input [type = 'checkbox']"). prop ("checked", true); This section describes how to set these attributes in checkbox selection and // jQuery.
Author: yue7603835