Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.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/0/amazon-s3/2.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
如何使用jQuery获取文本节点的值 5 6._Jquery - Fatal编程技术网

如何使用jQuery获取文本节点的值 5 6.

如何使用jQuery获取文本节点的值 5 6.,jquery,Jquery,如何获取文本节点的值?若我使用text()方法,它会连接两个值。若您想要一个文本值数组,请使用map,例如 <div class="count">5</div> <div class="count">6</div> 那怎么办 $('div.class').map(function() { return $(this).text(); }) 例如,如果你有几个,想获得第三名,你可以这样做 $("div.count:first").text();

如何获取文本节点的值?若我使用text()方法,它会连接两个值。

若您想要一个文本值数组,请使用map,例如

<div class="count">5</div>
<div class="count">6</div>
那怎么办

$('div.class').map(function() { return $(this).text(); })
例如,如果你有几个,想获得第三名,你可以这样做

$("div.count:first").text();

您需要循环从
$(“.count”)
生成的集合,然后获取循环中每个集合的
text()
值。

您可以使用此

$("div.count:eq(2)").text();

实际上,我需要使用div包含的值来设置div的宽度
$(".count:first").text()
$(".count:last").text()