这篇文章主要介绍了 jQuery 针对 input 的 class 属性写了多个值情况下的选择方法, 结合实例形式对比分析了 jQuery 选择器针对 class 属性中有多个值情况下的选中方法, 需要的朋友可以参考下
jQuery 是一个兼容多浏览器的 javascript 框架,核心理念是 write less,do more(写得更少, 做得更多)。jQuery 在 2006 年 1 月由美国人 John Resig 在纽约的 barcamp 发布,吸引了来自世界各地的众多 JavaScript 高手加入,由 Dave Methvin 率领团队进行开发。
本文实例讲述了 jQuery 针对 input 的 class 属性写了多个值情况下的选择方法。分享给大家供大家参考,具体如下:
jQuery 选择 input 的 class 属性写了多个值的情况:
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <script src="jquery-1.6.2.js" type="text/javascript"></script>
- <style type="text/CSS">
- .content {
- text-align: left;
- font-weight: normal;
- color: #000000;
- font-size: 9pt;
- vertical-align: bottom;
- }
- .my_sh {
- }
- </style>
- <script type="text/javascript">
- function getClassVal(){
- jQuery("#1").val(); //只能取到一个id的值
- jQuery(".content.my_sh").show(); //可以显示所有input框
- }
- </script>
- </head>
- <body>
- <input type="text" id="1" class="content my_sh" value="1" />
- <input type="text" id="2" class="content my_sh" value="2" />
- <input type="text" id="3" class="content my_sh" value="3" />
- <input type="text" id="4" class="content my_sh" value="4" />
- </body>
- </html>
【注】:input 中的 class 属性中的多个值之间要有空格,jQuery 在取值的时候每个 class 值之间不能有空格。
希望本文所述对大家 jQuery 程序设计有所帮助。
来源: http://www.phperz.com/article/17/0227/265187.html