从td元素

时间:2017-01-17 15:50:40

标签: javascript html

我有以下元素:

<td>
<div class="myClass" id="grid_ctl00_ctl04_f18036c">
    <ul class="rtUL rtLines">
        <li class="rtLI rtFirst rtLast">
            <div class="rtMid">
                <div style="color: rgb(0, 0, 0);" data-valueslistvalueid="69118">
                    <img title="Medium" alt="Medium" src="/ball_yellow.gif">
                </div>
            </div>
        </li>
    </ul>
</div>
</td>

我想采用img的 src属性文本,我有表格行,col。

for (var i = 1, row; row = table.rows[i]; i++) {
     var col = able.rows[i][0];
}

*我只能使用JaveScript。

感谢。

2 个答案:

答案 0 :(得分:3)

如果您的变量col选择了正确的列,请尝试:

module int_adaptive
implicit none
contains

subroutine RK4nd(f_x, norder, nvar, x_0, t_0, t_f, x_out, t_out)
    INTERFACE
        FUNCTION f_x (x_0, t_0)
            integer, parameter  :: dp=kind(0.d0)
            REAL(dp), INTENT(IN)    :: x_0(2, 3), t_0
            REAL, intent(out)   :: f_x(2,3)
        END FUNCTION f_x
    END INTERFACE


    integer, parameter  :: dp=kind(0.d0)
    integer             :: norder, i, nvar
    external            :: f_x
    real(dp), intent(in):: x_0(norder, nvar), t_0, t_f
    real(dp)            :: x_out(norder, nvar), t_out, k1(norder, nvar), y1(norder, nvar), y(norder, nvar)
    real(dp)            :: k2(norder, nvar), k3(norder, nvar), k4(norder, nvar),&
                           y2(norder, nvar), y3(norder, nvar), y4(norder, nvar)!, f_x(norder, nvar)
    real(dp)            :: h_min, h_0, h_max, tol, err_est, h, t

    if (h_0<h) then
        h = h_0
    end if
    if ((t_f - t_0) < 0.0) then
        h = -h
    end if
    t = t_0
    y = x_0

    do while (t .NE. t_f)
        k1 = f_x(y, t)
        y1 = y + k1*h/2.0

        k2 = f_x(y1, t+h/2.0)
        y2 = y + k2*h/2.0

        k3 = f_x(y2, t+h/2.0)
        y3 = y + k3*h

        k4 = f_x(y3, t+h)
        y4 = y + (k1+ 2*k2 + 2*k3 +k4)*h/6.0

        t = t + h
        y = y4

    end do

    x_out = y
    t_out = t

end subroutine
end module

答案 1 :(得分:0)

在单元格中获取img元素,并根据您的要求从元素对象中获取src属性或属性。

// assumes `table` refers to the DOM object of table

for (var i = 1, row; i < table.rows.length; i++) {
     // get src property
     var src = table.rows[i].cells[0].querySelector('img').src;
     // or get attribute value
     var src1 = table.rows[i].cells[0].querySelector('img').getAttribute('src');
}

var table = document.getElementById('table');

for (var i = 1, row; i < table.rows.length; i++) {
  // get src property
  var src = table.rows[i].cells[0].querySelector('img').src;
  // or get attribute value
  var src1 = table.rows[i].cells[0].querySelector('img').getAttribute('src');
  console.log(src);
  console.log(src1);
}
<table id="table">
  <tr>
    <td>
      <div class="myClass" id="grid_ctl00_ctl04_f18036c">
        <ul class="rtUL rtLines">
          <li class="rtLI rtFirst rtLast">
            <div class="rtMid">
              <div style="color: rgb(0, 0, 0);" data-valueslistvalueid="69118">
                <img title="Medium" alt="Medium" src="/ball_yellow.gif">
              </div>
            </div>
          </li>
        </ul>
      </div>
    </td>
  </tr>
  <tr>
    <td>
      <div class="myClass" id="grid_ctl00_ctl04_f18036c">
        <ul class="rtUL rtLines">
          <li class="rtLI rtFirst rtLast">
            <div class="rtMid">
              <div style="color: rgb(0, 0, 0);" data-valueslistvalueid="69118">
                <img title="Medium" alt="Medium" src="/ball_yellow.gif">
              </div>
            </div>
          </li>
        </ul>
      </div>
    </td>
  </tr>
  <tr>
    <td>
      <div class="myClass" id="grid_ctl00_ctl04_f18036c">
        <ul class="rtUL rtLines">
          <li class="rtLI rtFirst rtLast">
            <div class="rtMid">
              <div style="color: rgb(0, 0, 0);" data-valueslistvalueid="69118">
                <img title="Medium" alt="Medium" src="/ball_yellow.gif">
              </div>
            </div>
          </li>
        </ul>
      </div>
    </td>
  </tr>
  <tr>
    <td>
      <div class="myClass" id="grid_ctl00_ctl04_f18036c">
        <ul class="rtUL rtLines">
          <li class="rtLI rtFirst rtLast">
            <div class="rtMid">
              <div style="color: rgb(0, 0, 0);" data-valueslistvalueid="69118">
                <img title="Medium" alt="Medium" src="/ball_yellow.gif">
              </div>
            </div>
          </li>
        </ul>
      </div>
    </td>
  </tr>
  <tr>
    <td>
      <div class="myClass" id="grid_ctl00_ctl04_f18036c">
        <ul class="rtUL rtLines">
          <li class="rtLI rtFirst rtLast">
            <div class="rtMid">
              <div style="color: rgb(0, 0, 0);" data-valueslistvalueid="69118">
                <img title="Medium" alt="Medium" src="/ball_yellow.gif">
              </div>
            </div>
          </li>
        </ul>
      </div>
    </td>
  </tr>
</table>