Discuz教程网

JQuery里面的几种选择器 查找满足条件的元素$("#控件ID")

[复制链接]
authicon dly 发表于 2011-9-8 16:33:43 | 显示全部楼层 |阅读模式
样式:$(function (){
$("要选择的标签").click(function (){alert ("弹出对话框内容");})
});
第一种:Id选择器
用法:
  1. <head>
  2. <title></title>
  3. <script src ="Jq/jquery-1.4.2.js" type ="text/javascript" ></script>
  4. <script type ="text/javascript">
  5. $(function (){
  6. $("p").click(function (){alert ("小P");})
  7. });
  8. </script>
  9. </head>

  10. <body>
  11. <input type="button" value ="PlayGame" id="btnClick" />
  12. <p>第一个</p>
  13. <p>第二个</p>
  14. </body>
复制代码

说明:对所有<P>标签点击都有弹出对话框的提示
第二种:CSS选择器
  1. <head>
  2. <title></title>
  3. <script src ="Jq/jquery-1.4.2.js" type ="text/javascript" ></script>
  4. <script type ="text/javascript">
  5. $(function (){
  6. $(".warning").click(function (){alert("这是警告信息");});
  7. });
  8. </script>
  9. <style type="text/css" >
  10. .warning{background-color :Yellow ;color :Red ;}
  11. </style>
  12. </head>

  13. <body>
  14. <p>没有警告</p>
  15. <div class ="warning " >请带好小孩</div>
  16. <p class ="warning ">再次警告你</p>
  17. <input class ="warning " type ="button" value ="别点啊" />
  18. </body>
复制代码

说明:对所有CSS样式为:.warning点击都有弹出对话框的提示
第三种:多条件选择器
  1. <head>
  2. <title></title>
  3. <script src ="Jq/jquery-1.4.2.js"></script>
  4. <script type ="text/javascript" >
  5. $(function (){
  6. $(".docc,p,#txt1").click(function (){alert ("不要上当啊");})
  7. })
  8. </script>
  9. <style type="text/css" >
  10. .docc{background-color :Fuchsia ;color :Olive ;}
  11. </style>
  12. </head>

  13. <body>
  14. <p>电脑热卖</p>
  15. <input type ="text" id="txt1" />
  16. <input class ="docc" type ="button" value ="上当" />
  17. <input type ="checkbox" />
  18. </body>
复制代码

说明:可以对多个同时选中做处理。



上一篇:基于JQuery的Select选择框的华丽变身
下一篇:jQuery页面滚动浮动层智能定位实例代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-2 16:36

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表