Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript或jquery从html标记中提取整数_Javascript_Jquery_Math - Fatal编程技术网

javascript或jquery从html标记中提取整数

javascript或jquery从html标记中提取整数,javascript,jquery,math,Javascript,Jquery,Math,我试图从下面的标记中提取第二个整数 <div class="orbit-slide-number"> <span>1</span> of <span>3</span> </div> 1. 属于 3. 如果我尝试$('.orbit幻灯片编号span:last child')它返回:3,这很接近,我是否应该去掉span标签并结束?使用javascript不是很好 (最终目标:我将取整数并运行一些简单的

我试图从下面的标记中提取第二个整数

<div class="orbit-slide-number">
   <span>1</span> 
   of 
   <span>3</span>
</div>

1.
属于
3.
如果我尝试
$('.orbit幻灯片编号span:last child')
它返回:
3
,这很接近,我是否应该去掉span标签并结束?使用javascript不是很好

(最终目标:我将取整数并运行一些简单的数学1000/整数——使用该数学来指定新元素的宽度。)

var x = $('.orbit-slide-number span:last-child').text();
console.log(x);
这将输出:
3

如果希望引用
x
作为中的整数,可以使用:

+x //returns numeric representation of x
做:

这将输出:
3

如果希望引用
x
作为中的整数,可以使用:

+x //returns numeric representation of x
请尝试以下方法:

var secondValue = $('.orbit-slide-number span:last-child').html();
请尝试以下方法:

var secondValue = $('.orbit-slide-number span:last-child').html();

这将为您提供3 as字符串:

$('.orbit-slide-number span:last-child').text();
但是如果你想用它来做一些数学运算,你需要一个整数/数字

var val=parseInt($('.orbit-slide-number span:last-child').text());

这将为您提供3 as字符串:

$('.orbit-slide-number span:last-child').text();
但是如果你想用它来做一些数学运算,你需要一个整数/数字

var val=parseInt($('.orbit-slide-number span:last-child').text());

没有标签。当HTML到达浏览器时,它被解析为DOM。您需要提取
span
节点的嵌套文本内容的值。您看到的标记是渲染。换句话说,对节点进行分析,并将其转换为HTML表示。没有标记。当HTML到达浏览器时,它被解析为DOM。您需要提取
span
节点的嵌套文本内容的值。您看到的标记是渲染。换句话说,对节点进行分析并将其转换为HTML表示。