0

链接在这里; http://heart.bmj.com/content/early/2016/08/10/heartjnl-2016-310003.long

我有;

<span class="cit-title">
    <span class="cit-series-title">Original article
        <span class="cit-sep cit-sep-after-article-series-title">:</span>
    </span>Pregnancy outcomes in patients with pulmonary arterial hypertension associated with congenital heart disease 
</span>

到目前为止我做了什么?

我选择span.cit-title但它是innerText

给我;

"Original article: Pregnancy outcomes in patients with pulmonary arterial hypertension associated with congenital heart disease"

我只想得到

"Pregnancy outcomes in patients with pulmonary arterial hypertension associated with congenital heart disease"` 

部分。

如何使用类排除跨度cit-series-title并获取原始文本?

4

6 回答 6

0

您想要的文本是.cit-series-title. 您可以选择该元素并使用 javascriptNode.nextSibling来获取它的下一个兄弟文本。

var text = $(".cit-title > .cit-series-title")[0].nextSibling.textContent;
console.log(text);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span class="cit-title">
    <span class="cit-series-title">Original article
        <span class="cit-sep cit-sep-after-article-series-title">:</span>
    </span>Pregnancy outcomes in patients with pulmonary arterial hypertension associated with congenital heart disease 
</span>

于 2016-09-28T10:06:01.523 回答
0

您可以先获取整个cit-title元素的内容...

var wholeElementText = $('.cit-title').text();

...然后只获取标题文本...

var titleText = $('.cit-title .cit-series-title').text();

...然后titleText_wholeElementText

var justThePartYouWant = wholeElementText.replace(titleText, '');
于 2016-09-28T10:06:07.733 回答
0

从中选择数据span.cit-title并将其存储到变量中A,然后从中选择数据span.cit-series-title并将其存储到变量中B

然后做喜欢A.replace(B, '');它会工作

于 2016-09-28T10:06:59.100 回答
0

alert($(".cit-title").clone()    
           .children() 
           .remove()   
           .end()      
          .text());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span class="cit-title">
    <span class="cit-series-title">Original article
        <span class="cit-sep cit-sep-after-article-series-title">:</span>
    </span>Pregnancy outcomes in patients with pulmonary arterial hypertension associated with congenital heart disease 
</span>

于 2016-09-28T10:08:30.283 回答
0

我会将 div 存储在一个临时变量中,以便删除不需要的元素并获取文本。

var div = $(".cit-title").clone();
div.find("span").first().remove();
div.text();
于 2016-09-28T10:09:09.460 回答
-1

我认为更好的解决方案是将其他文本包装在另一个跨度中,如下所示:

<span class="cit-title">
    <span class="cit-series-title">Original article<span class="cit-sep cit-sep-after-article-series-title">:</span> </span><span class="cit-series-description">Pregnancy outcomes in patients with pulmonary arterial hypertension associated with congenital heart disease</span> </span>

然后你从.cit-series-description容器中获取内部文本。

干杯

于 2016-09-28T10:03:04.387 回答