jQuery_API_03_Attributes

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明。否则将追究法律责任。http://blog.csdn.net/mayongzhan - 马永占,myz,mayongzhan

<!DOCTYPE html PUBLIC "-//W<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /><chmetcnv w:st="on" tcsc="0" numbertype="1" negative="False" hasspace="False" sourcevalue="3" unitname="C">3C</chmetcnv>//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Language" content="utf-8" />

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<meta name="author" content="马永占(MyZ)" />

<meta name="Copyright" content="马永占(MyZ)" />

<meta name="description" content="" />

<meta name="keywords"content="" />

<link rel="icon" href="" type="image/x-icon" />

<link rel="shortcut icon" href="" type="image/x-icon" />

<link href="" rel="stylesheet" type="text/css" />

<title></title>

<style type="text/css">

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

</style>

<script type="text/javascript" src="jquery-<chsdate w:st="on" isrocdate="False" islunardate="False" day="30" month="12" year="1899">1.2.6</chsdate>.js"></script>

</head>

<body>

<script type="text/javascript">

$("document").ready(function(){

////////////////////////////////////////////////////////////////////////////////////////

//Attr:

//attr( name ) Returns: Object

//Access a property on the first matched element. This method makes it easy to retrieve a property value from the first matched element. If the element does not have an attribute with such a name, undefined is returned. Attributes include title, alt, src, href, width, style, etc.

// var title = $("em").attr("title");

// $("div").text(title);

//attr( properties ) Returns: jQuery

//Set a key/value object as properties to all matched elements.

// $("img").attr({

// src: "/images/hat.gif",

// title: "jQuery",

// alt: "jQuery Logo"

// });

// $("div").text($("img").attr("alt"));

//attr( key, value ) Returns: jQuery

//Set a single property to a value, on all matched elements.

//$("button:gt(1)").attr("disabled","disabled");

//attr( key, fn ) Returns: jQuery

//Set a single property to a computed value, on all matched elements.

// $("div").attr("id", function (arr) {

// return "div-id" + arr;

// })

// .each(function () {

// $("span", this).html("(ID = '<b>" + this.id + "</b>')");

// });

//removeAttr( name ) Returns: jQuery

//Remove an attribute from each of the matched elements.

// $("button").click(function () {

// $(this).next().removeAttr("disabled")

// .focus()

// .val("editable now");

// });

////////////////////////////////////////////////////////////////////////////////////////

//Class:

//addClass( class ) Returns: jQuery

//Adds the specified class(es) to each of the set of matched elements.

//$("p:last").addClass("selected");

//hasClass( class ) Returns: Boolean

//Returns true if the specified class is present on at least one of the set of matched elements.

//$("div#result1").append($("p:first").hasClass("selected").toString());

//$("div#result2").append($("p:last").hasClass("selected").toString());

//$("div#result3").append($("p").hasClass("selected").toString());

//removeClass( class ) Returns: jQuery

//Removes all or the specified class(es) from the set of matched elements.

//$("p:even").removeClass("blue");

//toggleClass( class ) Returns: jQuery

//Adds the specified class if it is not present, removes the specified class if it is present.

// $("p").click(function () {

// $(this).toggleClass("highlight");

// });

////////////////////////////////////////////////////////////////////////////////////////

//HTML:

//html( ) Returns: String

//Get the html contents (innerHTML) of the first matched element. This property is not available on XML documents (although it will work for XHTML documents).

// $("p").click(function () {

// var htmlStr = $(this).html();

// $(this).text(htmlStr);

// });

//html( val ) Returns: jQuery

//Set the html contents of every matched element. This property is not available on XML documents (although it will work for XHTML documents).

//$("div").html("<span class='red'>Hello <b>Again</b></span>");

////////////////////////////////////////////////////////////////////////////////////////

//Text:

//text( ) Returns: String

//Get the combined text contents of all matched elements.

// var str = $("p:first").text();

// $("p:last").html(str);

//text( val ) Returns: jQuery

//Set the text contents of all matched elements.

// var str = $("p:first").text();

// $("p:last").html(str);

////////////////////////////////////////////////////////////////////////////////////////

//Value:

//val( ) Returns: String, Array

//Get the content of the value attribute of the first matched element.

// $("input").keyup(function () {

// var value = $(this).val();

// $("p").text(value);

// }).keyup();

//val( val ) Returns: jQuery

//Set the value attribute of every matched element.

// $("button").click(function () {

// var text = $(this).text();

// $("input").val(text);

// });

//val( val ) Returns: jQuery

//Checks, or selects, all the radio buttons, checkboxes, and select options that match the set of values.

// $("#single").val("Single2");

// $("#multiple").val(["Multiple2", "Multiple3"]);

// $("input").val(["check1","check2", "radio1" ]);

////////////////////////////////////////////////////////////////////////////////////////

</script>

</body>

</html>

你可能感兴趣的:(JavaScript,html,jquery,XHTML,Office)