此标签的正确选择器

Proper selector for this tag?

本文关键字:选择器 标签      更新时间:2023-09-26

我似乎找不到适合这个标签的jquery选择器:

HTML:

<div class="span4 span4-mod">
    <div class="well well-mod">
    <h4 class="DomainDescription">Iniz LAX1</h4>
    <span class="btn-block">
        <button></button>
    </span>
    <form action="pinfo.php" method="post">
        <input type="hidden" value="">
        <button>History</button>    
    </form>
    Port Status<br />
    <span class="portstatus porton">21</span>
    <table class="table" style="margin-top: 10px;">
        <tbody>
            <tr>
                <td><strong>Distro:</strong></td>
                <td class="showdistro">Debian 7.1</td>
            </tr>
            <tr>
                <td><strong>Online since: </strong></td>
                <td class="showonline">2 Days 10:29</td>
            </tr>
        </tbody>
    </table>    
</div>

我试图搜索类"DomainDescription",然后在类"showonline"中搜索HTML,并操作后者。

我正在寻找兄弟姐妹(表)>child(tbody)>child(tr)>child(td)的关系

尽管我尽力了,但我似乎找不到合适的人选来处理这种关系。

我的起点是:

$('.DomainDescription').each(function () {                  
    var PrintedUptime=$(this).siblings().children(".showonline").html();
    alert (PrintedUptime);
});

合适的选择器应该是什么?

您可以

$('.DomainDescription').each(function () {                  
    var PrintedUptime=$(this).closest('.well-mod').find(".showonline").html();
    alert (PrintedUptime);
});

演示:Fiddle

正确的css选择器是:

.DomainDescriptor~table>tbody>tr>td>.showonline

我认为这至少是正确的。因此,您可以使用:

$('.DomainDescriptor~table>tbody>tr>td>.showonline').each(function(){
    alert(this.html());
})

以达到期望的效果。这没有经过测试。