慕课网:2-3.class 选择器(寻找红色铅笔)

来源:互联网 发布:阿里云备案拍照ps 编辑:程序博客网 时间:2024/06/09 17:38

1、每一个标签都有很多属性,如id、class都是属性,因此可以使用attr()输出出来。

2、上代码:

<!DOCTYPE html PUBLIC "-//W3C//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-Type" content="text/html; charset=utf-8" /><title>2-3.class 选择器(寻找红色铅笔)</title><script src="../js/jquery-1.6.4.js" type="text/javascript"></script><script type="text/javascript">$(function(){//$("#default").hide(); //用来判定是否找到了该标签。$("div#divtest").attr("edi","30");  //改行添加了一个属性//<div edi = "30" id = "divtest">div的内容</div>$("div").css("background-color","red");alert($("div.red").attr("class"));$("div.red").html($("div.red").attr("class"));});</script></head><body>    <div id="divtest">div的内容</div>    <div id="default" value = "123456" class = "red">1234</div></body></html>

0 0