jquery - 如何使用 JQuery 在标签内查找文本
问题描述
嗨,我有一段如下所示
<p>The strength of the notion of the cultural biography, in my mind, is that it provides us with a way to escape from these preoccupations <xref>1990</xref>. The algorithm takes a set of earthly 1989 biographies as input and produces a set of improved resurrection 1915 biographies as output.</p>
我需要在标签中找到未标记的年份<p>
。我尝试了一个代码,请检查下面
if($xml.find("p").length > 0)
{
var $element = $xml.find("p").addBack("p");
$element.each(function()
{
if($(this).clone().find('xref').remove().end().text().match(/19+[0-9][0-9]/))
{
//*****
}
});
}
但是这段代码返回单个未标记的年份,我想要一段完整的年份列表
解决方案
$(document).ready(function(){
var $container=$(this).find("xref").remove().text().match(/\d+/g);
var num =$(this).find("#value").text().match(/\d+/g).join(",");
console.log( num);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<p id="value">The strength of the notion of the cultural biography, in my mind, is that it provides us with a way to escape from these preoccupations <xref>1990</xref> The algorithm takes a set of earthly 1989 biographies as input and produces a set of improved resurrection 1915 biographies as output.</p>
推荐阅读
- javascript - 时差一小时的时间范围
- c++ - OpenGL 不会使用 Shaders Mac 渲染
- http - 使用 PoolingHttpClientConnectionManager 和 CloseableHttpClient 发送空闲连接的保持活动请求
- python - 如何在没有 CUDA 的情况下为 PyTorch 构建 CUDA 自定义 C++ 扩展?
- javascript - 部分字符串匹配 - 动态字符串
- xamarin.forms - Xamarin.Forms - 选择键盘语言
- firebase - Flutter Firebase 依赖项和服务
- javascript - 仅从地图(其值为数组)中获取值到数组打字稿
- flutter - Flutter/ReactiveForms:如何在 ReactiveTextField 中处理与 TextFormField 中相同的控制器?
- java - 如何从地图中分配元素,以使元素总和不增加上限