得到一个div下 特定ID的所有标签。解决方法
得到一个div下 特定ID的所有标签。。。
比如说得到
<div id="showsp">
<div id="a"></div>
<div id="a"></div>
<div id="a"></div>
<span id="a"></span>
</div>
得到 <div id="showsp"> 下所有id=a 的标签
谢谢了
------解决方案--------------------
比如说得到
<div id="showsp">
<div id="a"></div>
<div id="a"></div>
<div id="a"></div>
<span id="a"></span>
</div>
得到 <div id="showsp"> 下所有id=a 的标签
谢谢了
------解决方案--------------------
- HTML code
<!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=gb2312" /> <title>无标题文档</title> <script src="jquery-1.3.2.js"></script> <script> $(document).ready(function(){ alert($("#showsp").html())//大标签showsp下的所有class 为a的div var html=''; $(".a").each(function(){ html +=$(this).text();//每个class为a的div的text值 }); alert(html) alert($("#showsp [name=a]").html())//默认的会取值第一个 }); </script> </head> <body> <div id="showsp"> <div class="a" name="a">1111</div> <div class="a" name="a">2222</div> <div class="a" name="a">3333</div> <span class="a" name="a">4444</span> </div> </body> </html>