Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.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 从类中的类返回值_Javascript_Jquery_Html - Fatal编程技术网

Javascript 从类中的类返回值

Javascript 从类中的类返回值,javascript,jquery,html,Javascript,Jquery,Html,这就是我正在使用的html <table class="forum_unread" id="post1093990"> <td class="body"> <div id="content1093990" class="postcontent"> 899,906 </div> </td> </table> 由于某种原因,控制台返回undefined。bo

这就是我正在使用的html

<table class="forum_unread" id="post1093990">
    <td class="body">
        <div id="content1093990" class="postcontent">
            899,906
        </div>
   </td>
</table>

由于某种原因,控制台返回undefined

。body
不是
的同级。forum\u unread

试试这个:

var a = $(".forum_unread .postcontent").text();
console.log(a);

.body
不是
论坛的
兄弟姐妹
。它是
子项
。您使用
链接的每一步
都会自动返回一个值。尝试将每个步骤存储在变量中。那可能就很清楚了…使用
$(.forum\u unread.postcontent').text()
@Yuri-你把孩子和后代弄糊涂了。我不是我祖父的孩子。请不要因为你觉得问题太简单就否决这些问题。OP正确地解释了问题以及出错的原因,因为id是一个变量,在每个帖子中都会发生变化。我正在尝试使用常量。
var a = $(".forum_unread .postcontent").text();
console.log(a);