0

タグの数レベル下にネストされたテーブル行をループしたい<table>

私ができると思ったのは、

var row = jQuery("#views-form-transport-files-page > table > tbody > tr");
jQuery.each(row, function(index, value){
    console.log(value);
});

私のブラウザ コンソールでは、何も出力されません。ただし、親に近い要素など、いくつかの要素を出力してみました。ほとんどの場合、ほとんどの要素を介して出力したい場合console.log(".my-element-with-children");、結果として空の角括弧が得られ、手にオブジェクトができます。

したがって、これらの s をターゲットにしてそれらをループする方法について本当に困惑しています。trこのelement > element > element方法を使用できない場合は?

    <div class="view view-transport-files view-id-transport_files view-display-id-page transport-files-view view-dom-id-03505a184244d1fde35eac370a04bbf4">

      <div class="view-filters">
      <form action="/transport-files" method="get" id="views-exposed-form-transport-files-page" accept-charset="UTF-8"><div><div class="views-exposed-form">
  <div class="views-exposed-widgets clearfix">
          <div id="edit-field-transp-file-number-value-wrapper" class="views-exposed-widget views-widget-filter-field_transp_file_number_value">
                  <label for="edit-field-transp-file-number-value">
            Transport file number filter          </label>
                        <div class="views-widget">
          <div class="form-item form-type-textfield form-item-field-transp-file-number-value">
 <input type="text" id="edit-field-transp-file-number-value" name="field_transp_file_number_value" value="" size="30" maxlength="128" class="form-text" />
</div>
        </div>
      </div>
                    <div class="views-exposed-widget views-submit-button">
      <input type="submit" id="edit-submit-transport-files" name="" value="Apply" class="form-submit" />    </div>
      </div>
</div>
</div></form>    </div>


      <div class="view-content">
      <div class="views-form"><form action="/transport-files" method="post" id="views-form-transport-files-page" accept-charset="UTF-8"><div><input type="hidden" name="form_build_id" value="form-5qC8G26t49Mw4209HaFKb6GSX4Cnzt3sIsrcUvOobB8" />
<input type="hidden" name="form_token" value="rN22iXS4r0LeXV3rEEaAcVbWi8hOtvG_GyVP6PYICLQ" />
<input type="hidden" name="form_id" value="views_form_transport_files_page" />
<table class="views-table cols-29" >
        <thead>
      <tr>
                  <th class="views-field views-field-field-transp-file-number" >
            <a href="/transport-files?field_transp_file_number_value=&amp;order=field_transp_file_number&amp;sort=asc" title="sort by Transport file number" class="active">Transport file number</a>          </th>
                  <th class="views-field views-field-field-tf-customer" >
            Client          </th>
                  <th class="views-field views-field-field-tf-trailer-nr" >
            Trailer number          </th>

              </tr>
    </thead>
    <tbody>
          <tr class="odd transport-files-row views-row-first">
                  <td class="views-field views-field-field-transp-file-number" >
            <a href="/node/192/edit">43100021</a>          </td>
                  <td class="views-field views-field-field-tf-customer" >
                      </td>
                  <td class="views-field views-field-field-tf-trailer-nr" >
            Trailer 3          </td>
                  <td class="views-field views-field-field-transp-file-load-date" >
            <span class="date-display-single">2012-10-24</span>          </td>
                  <td class="views-field views-field-field-tf-loading-place" >
                      </td>
                  <td class="views-field views-field-field-tf-driver-loading" >
                      </td>
                  <td class="views-field views-field-field-tf-deliv-ferry-comp" >
                      </td>
                  <td class="views-field views-field-field-deliv-ferry-price" >
                      </td>
                  <td class="views-field views-field-field-transp-file-deliv-date" >
            2012-10-24 00:00:00          </td>
                  <td class="views-field views-field-field-tf-delivery-place" >
                      </td>
                  <td class="views-field views-field-field-tf-driver-deliverty" >
                      </td>
                  <td class="views-field views-field-field-tf-invoice-nr" >
            3366554488          </td>
                  <td class="views-field views-field-field-tf-price-amount  views-field-editablefield" >
            <div id="editablefields-field-tf-price-amount" class="editablefield-item"><div class="field-type-number-float field-name-field-tf-price-amount field-widget-number form-wrapper" id="edit-field-tf-price-amount-0-field-tf-price-amount"><div                               id="field-tf-price-amount-0-field-tf-price-amount-add-more-wrapper"><div class="form-item form-type-textfield form-item-field-tf-price-amount-0-field-tf-price-amount-und-0-value">
  <input type="text" id="edit-field-tf-price-amount-0-field-tf-price-amount-und-0-value" name="field_tf_price_amount[0][field_tf_price_amount][und][0][value]" value="5000" size="12" maxlength="10" class="form-text" />
</div>
</div></div><div class="form-actions form-wrapper" id="edit-field-tf-price-amount-0-actions"><input type="submit" id="edit-field-tf-price-amount-0-actions-submit" name="submit-field_tf_price_amount-0" value="Save" class="form-submit" /></div></div>          </td>
                  <td class="views-field views-field-field-transp-file-currency  views-field-editablefield" >
            <div id="editablefields-field-transp-file-currency" class="editablefield-item"><div class="field-type-list-text field-name-field-transp-file-currency field-widget-options-select form-wrapper" id="edit-field-transp-file-currency-0-field-transp-file-currency"><div class="form-item form-type-select form-item-field-transp-file-currency-0-field-transp-file-currency-und">
  <label for="edit-field-transp-file-currency-0-field-transp-file-currency-und"> <span class="form-required" title="This field is required.">*</span></label>
 <select id="edit-field-transp-file-currency-0-field-transp-file-currency-und" name="field_transp_file_currency[0][field_transp_file_currency][und]" class="form-select required"><option value="€ "> €&lt;/option><option value="£ " selected="selected"> £</option></select>
</div>
</div><div class="form-actions form-wrapper" id="edit-field-transp-file-currency-0-actions"><input type="submit" id="edit-field-transp-file-currency-0-actions-submit" name="submit-field_transp_file_currency-0" value="Save" class="form-submit" /></div></div>          </td>
                  <td class="views-field views-field-clone-node" >
            <a href="/node/192/clone?destination=transport-files">clone</a>          </td>
                  <td class="views-field views-field-field-tf-baf-eb  views-field-editablefield" >
            <div id="editablefields-field-tf-baf-eb" class="editablefield-item"><div class="field-type-number-float field-name-field-tf-baf-eb field-widget-number form-wrapper" id="edit-field-tf-baf-eb-0-field-tf-baf-eb"><div id="field-tf-baf-eb-0-field-tf-baf-eb-add-more-wrapper"><div class="form-item form-type-textfield form-item-field-tf-baf-eb-0-field-tf-baf-eb-und-0-value">
  <input type="text" id="edit-field-tf-baf-eb-0-field-tf-baf-eb-und-0-value" name="field_tf_baf_eb[0][field_tf_baf_eb][und][0][value]" value="" size="12" maxlength="10" class="form-text" />
</div>
           <td class="views-field views-field-field-tf-shunts-enz" >

                  <td class="views-field views-field-field-tf-with" >
                      </td>
                  <td class="views-field views-field-field-tf-ex" >
                      </td>
                  <td >
            <a href="/transport-file/mail/192">Mail sturen</a>          </td>
              </tr>
      </tbody>
</table>

入れ子になった入力要素をターゲットにして適用.onfocus();し、.onfocus();それらの値を計算して同じ行の別の入力要素に入れるという考え方です。tableしたがって、基本的に私のクライアントは、これを Excel シートのような機能で使用したいと考えています。

本来、このテーブルには行ごとにもっと多くの td がありますが、多くの td は構造が似ているため、この短い html を貼り付けました。

4

1 に答える 1

0

jQuery.each()は単純なオブジェクトまたは配列をループするためのものですが、jquery オブジェクトをループするには、次のように.each()メソッドを使用することをお勧めします。

var row = jQuery("#views-form-transport-files-page > table > tbody > tr");
row.each(function(i) {
   console.log( $(this)[0].tagName );
});
于 2012-10-31T09:23:15.287 に答える