如何使用javascript获取div中的子节点 [英] how to get the child node in div using javascript

查看:118
本文介绍了如何使用javascript获取div中的子节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的div结构:

 < div id =ctl00_ContentPlaceHolder1_Jobs_dlItems_ctl01_a
onmouseup = checkMultipleSelection(此,事件);>
< table cellpadding =0cellspacing =0border =0width =100%>
< tr>
< td style =width:50px; text-align:left;> 09:15 AM< / td>
< td style =width:50px; text-align:left;> Item001< / td>
< td style =width:50px; text-align:left;> 10< / td>
< td style =width:50px; text-align:left;> Address1< / td>
< td style =width:50px; text-align:left;> 46545465< / td>
< td style =width:50px; text-align:left;> ref1< / td>
< / tr>
< / table>
< / div>

现在,如果我有div的id,我怎么能得到这个时间和地址div使用JavaScript?
解析方案 var tds = document.getElementById(ctl00_ContentPlaceHolder1_Jobs_dlItems_ctl01_a)。的getElementsByTagName( TD);
time = tds [0] .firstChild.value;
address = tds [3] .firstChild.value;


Below is the structure of my div:

<div id="ctl00_ContentPlaceHolder1_Jobs_dlItems_ctl01_a"
    onmouseup="checkMultipleSelection(this,event);">
       <table cellpadding="0" cellspacing="0" border="0" width="100%">
           <tr>
              <td style="width:50px; text-align:left;">09:15 AM</td>
              <td style="width:50px; text-align:left;">Item001</td>
              <td style="width:50px; text-align:left;">10</td>
              <td style="width:50px; text-align:left;">Address1</td>
              <td style="width:50px; text-align:left;">46545465</td>
              <td style="width:50px; text-align:left;">ref1</td>
           </tr>
       </table>
</div>  

Now, if i have the id of the div, how can i get the time and address for this div using JavaScript?

解决方案

var tds = document.getElementById("ctl00_ContentPlaceHolder1_Jobs_dlItems_ctl01_a").getElementsByTagName("td");
time = tds[0].firstChild.value;
address = tds[3].firstChild.value;

这篇关于如何使用javascript获取div中的子节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆