使用javascript动态访问表的单元格

时间:2017-03-14 11:08:25

标签: javascript html dom

我有像这样的html页面层次结构,我想访问表格中的元素。“akshay1234530@yahoo.com”& “ajdlkjalkdjaldkjlakdjla”。

<body> //in body

            <div id="page_content"> <!--access this div-->

                 <div id="page_settings_modal">

                 <div class="sqlqueryresults ajax"> <!-- then access this div-->

                          <div class="result_query" style="text-align: left">

                          <table class="navigation nospacing nopadding print_ignore">

                          <div class="common_hidden_inputs">

                          <form method="post" action="sql.php" name="displayOptionsForm" class="ajax print_ignore">

                          <form method="post" action="tbl_row_action.php" name="resultsForm"  class="ajax"> <!--access this form-->

                                   <div class="data" style="position: relative;"> <!-- access this div-->

                                             <table class="sticky_columns" style="position: fixed; z-index: 99; width: 568px; margin-left: 6.56px; top: 59px; display: none;">

                                             <table class="table_results ajax pma_table" data-uniqueid="24435"> <!--access this table-->

                                                   <tbody> <!--inside this tbody access the elements of tables in -->

                                                        <td data-decimals="0" data-type="string" data-originallength="23" class="data grid_edit click2 not_null   text ">
                                                                 <span>akshay1234530@yahoo.com</span>

                                                        </td>

                                                        <td data-decimals="0" data-type="blob" data-originallength="23" class="data grid_edit click2 not_null">
                                                                 <span>ajdlkjalkdjaldkjlakdjla</span>

                                                        </td>

我无法弄清楚如何在这个复杂的html页面中访问table的元素。请帮忙!!!!!!!

到目前为止我已尝试过这个

    var div1 = document.getElementById("page_content");  

    var div2=div1.getElementsByTagName("div")[1];

    var form1 = div2.getElementsByTagName("form")[2];

    var div3= form1.getElementsByTagName("div")[0];

    var table1=div3.getElementsByTagName("table")[1];

1 个答案:

答案 0 :(得分:0)

以下代码行将返回您需要的值

class FixColumnName < ActiveRecord::Migration
  def change
    rename_column :namespace_products, :namespace_category_id, :category_id
  end
end

1st - “akshay1234530@yahoo.com” 第二名 - “ajdlkjalkdjaldkjlakdjla”。