首先声明自己是刚学JQuery,提的问题弱智,大家不要笑$("div+p").addClass("P1");这个表达式是匹配DIV层后的第一个P元素,然后给它加样式P1.可是我用了后怎么也不能匹配..
大家帮忙看看是哪里不对 <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<style type="text/css">
.test{
background-color:Red;
color:Red;
}
</style>
<script type="text/javascript" src="jquery-1.3.2.min.js">
</script>
<script type="text/javascript">
//<![CDATA[
$(document).ready(function(){
$("div+p").addClass("test");
});
//]]>
</script>
</head>
<body>
<div><p>456</p></div>
<form id="form1" runat="server">
<div><p>123</p></div>
<div>
<p>这是第一个加号</p>
<div id="divTest">
<p>我测试+号</p>
</div>
<div><a href="#">test</a><p>这是第二个加号</p></div>
</div>
</form>
</body>
</html>
大家帮忙看看是哪里不对 <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<style type="text/css">
.test{
background-color:Red;
color:Red;
}
</style>
<script type="text/javascript" src="jquery-1.3.2.min.js">
</script>
<script type="text/javascript">
//<![CDATA[
$(document).ready(function(){
$("div+p").addClass("test");
});
//]]>
</script>
</head>
<body>
<div><p>456</p></div>
<form id="form1" runat="server">
<div><p>123</p></div>
<div>
<p>这是第一个加号</p>
<div id="divTest">
<p>我测试+号</p>
</div>
<div><a href="#">test</a><p>这是第二个加号</p></div>
</div>
</form>
</body>
</html>
<head runat="server">
<title>无标题页</title>
<style type="text/css">
.test{
background-color:Red;
color:Red;
}
</style>
<script type="text/javascript" src="jquery-1.3.2.min.js">
</script>
<script type="text/javascript">
//<![CDATA[
$(document).ready(function(){
$("div+p").addClass("test");
});
//]]>
</script>
</head>
<body>
<div><p>456</p></div>
<!--在这里添加一个p的元素-->
<p>789</p>
<form id="form1" runat="server">
<div><p>123</p></div>
<div>
<p>这是第一个加号</p>
<div id="divTest">
<p>我测试+号</p>
</div>
<div><a href="#">test</a><p>这是第二个加号</p></div>
</div>
</form>
</body>
</html>