读书人

JQuery种选择器只对原始类名元素起作用

发布时间: 2012-10-31 14:37:31 作者: rapoo

JQuery类选择器只对原始类名元素起作用
JQuery类选择器只对原始类名元素起作用,对后添加的class不起作用。

html代码:

 <body>  <h3 align="center">joeking</h3>  <hr>  <p>p1</p><br>  <p id="p">p2</p><br>  <p>p3</p>  <p name="code">$(document).ready(function(){$("p").click(function(){$("p").addClass("red");});$("#p").click(function(){$(this).removeClass("red");});$(".red").click(function(){alert("this is red");});});

css:
.red{color:red}p{text-align:center}


代码如上,只有单击p4标签时,才会弹出alert对话框。
使用火狐firebug查看html,所有的p元素都添加了class,但是为什么不起作用呢?

读书人网 >Web前端

热点推荐