求助,children()方法遇到的一些问题
时间:2009-10-09
来源:互联网
测试代码:
<table id=t1>
<tr>
<Td class=d1>Hello1</td>
</tr>
<tr class=d2>
<Td>Hello2</td>
</tr>
<tr>
<Td>Hello3</td>
</tr>
<tr>
<Td>Hello4</td>
</tr>
<tr>
<Td>Hello5</td>
</tr>
</table>
1. alert($('#t1').children().size()) 结果为1
alert($('#t1 tr').size()) 结果为5
这两者有什么区别呢?
2. alert($('tr').children('.d1').text()) 结果 Hello1
alert($('#t1').children('.d1').text()) 结果 空 ??
这里我也不太明白 children('**') 是只遍历 对应的直接子元素吗?二层儿子节点就没有遍历到?
alert($('#t1').children('.d2').html()) 结果 null , ??
这句就是查找直接子元素,为什么还是为null
3. alert($('#t1').children().children().text()) 结果Hello1Hello2Hello3Hello4Hello5
alert($('#t1').children().children().html()) 结果空
这又是什么原因呢?
望高手指教!!
<table id=t1>
<tr>
<Td class=d1>Hello1</td>
</tr>
<tr class=d2>
<Td>Hello2</td>
</tr>
<tr>
<Td>Hello3</td>
</tr>
<tr>
<Td>Hello4</td>
</tr>
<tr>
<Td>Hello5</td>
</tr>
</table>
1. alert($('#t1').children().size()) 结果为1
alert($('#t1 tr').size()) 结果为5
这两者有什么区别呢?
2. alert($('tr').children('.d1').text()) 结果 Hello1
alert($('#t1').children('.d1').text()) 结果 空 ??
这里我也不太明白 children('**') 是只遍历 对应的直接子元素吗?二层儿子节点就没有遍历到?
alert($('#t1').children('.d2').html()) 结果 null , ??
这句就是查找直接子元素,为什么还是为null
3. alert($('#t1').children().children().text()) 结果Hello1Hello2Hello3Hello4Hello5
alert($('#t1').children().children().html()) 结果空
这又是什么原因呢?


作者: js0218 发布时间: 2009-10-09
问题1:table的子集为tbody而不是tr
$('#t1 tr') == $('#t1>tbody>tr')
问题2:先学习一下DOM tree
问题3:jquery返回的始终是个collection,同问题1,
把代码改成alert($('#t1').children().children().parent().html()) 你就明白为什么错了
$('#t1 tr') == $('#t1>tbody>tr')
问题2:先学习一下DOM tree
问题3:jquery返回的始终是个collection,同问题1,
把代码改成alert($('#t1').children().children().parent().html()) 你就明白为什么错了
作者: zcrane 发布时间: 2009-10-09
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28