如何从jquery中获取dl标记HTML的值

how to get value of dl tag HTML from jquery

本文关键字:dl 标记 HTML 的值 获取 jquery      更新时间:2023-09-26

我想通过Jquery或Javascript从HTML文件中选择以下值。Bank Transfer,有人能建议我怎么做吗?

<div class="color-me" id="txnDetails">
  <div class="panel-apply-font-size">
    <div class="row">
      <div class="cols">
        <dl class="entityDetails-field">
          <dt>PaymentMethod</dt>
          <dd>Bank Transfer</dd>
        </dl>
      </div> <!--end of cols-->
      <div class="cols">
        <dl class="entityDetails-field">
          <dt>AccountNumber</dt>
          <dd>34343</dd>
        </dl>
      </div> <!--end of cols-->
      <div class="cols">
        <dl class="entityDetails-field">
          <dt>BankName</dt>
          <dd>Bank Of America</dd>
        </dl>
      </div> <!--end of cols-->
    </div><!--end of rows-->
  </div><!--end of panel-->
</div><!--end of color me-->

我是这样做的:

$("#txnDetails dd").on(function(){
    $(this)....
});

在这里,我没有为DTDD元素提供任何类名和ID标记,我如何到达第一个DD标记来选择它的文本?我想要第一个DD标签的文本,即值"银行转账"。

使用

$('#txnDetails dd:first').text()

$('#txnDetails').find('dd').first().text()

尝试:nth-child((选择器:

$("dd:nth-child(1)").text();

你只需要知道你要瞄准的元素的位置。

所需读数:

http://api.jquery.com/nth-child-selector/

您可以使用以下内容:

 $("#txnDetails dd").first().text()

您应该能够使用获取值

$('#txnDetails dd:first-child').val();