社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Jquery

jquery针对这个和类

Mads Hjorth • 5 年前 • 1189 次点击  

我试图从表中提取数据,更具体地说,是从列中的类中提取数据。

value = jQuery(this).closest('td').prev('td').prev('td').text();

在这个单元中,有两个类。 一个叫做:

.amount 

另一个叫:

.currency 

我要瞄准那个叫的。数量。

我试过遵循代码,但它给了我金额和货币。

value = jQuery(this).closest('td').prev('td').prev('td').find('.amount').text();

我做错什么了?

JQuery

jQuery('input').on('click', function() {
    if (jQuery(this).is(':checked')) {
        productName = jQuery(this).closest('td').prev('td').text();
        value = jQuery(this).closest('td').prev('td').prev('td.amount').text();
        jQuery(".spiseseddel ul").append('<li>' + productName + value + '</li>');
    } else {
        productName = jQuery(this).closest('td').prev('td').text();
        jQuery('.spiseseddel ul li').filter(function() {
            return jQuery.text([this]) === productName;
    }).remove();
    }
})

HTML

<tr>
    <td>
        <span class="amount">25,00
        <span class="currency">DKK</span>
        </span>
    </td>
    <td class="col-name">product name
    </td>
    <td class="add-to-cart">
    <input type="checkbox">
    </td>
</tr>
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/43354
 
1189 次点击  
文章 [ 2 ]  |  最新文章 5 年前
Oleg Olegovich
Reply   •   1 楼
Oleg Olegovich    6 年前

只需指定您需要的TD类:

value = jQuery(this).closest('td').prev('td').prev('td.amount').text();
Barmar
Reply   •   2 楼
Barmar    6 年前

使用 .find() 在您要瞄准的单元格中,而不是当前单元格中。

value = jQuery(this).closest('td').prev('td').prev('td').find(".amount").text();