你能帮我吗,我创建一个这样的嵌套列表:
/* include */
int main(){
/* init */
if(listen(defSock,5)==0)
printf("Listening\n");
else
printf("Error\n");
len = sizeof(cadd);
// while they're no error
while (1)
{
// wait for new connection
newSock = accept(defSock, (struct sockaddr *) &cadd, &len);
// test if client connection succeded
if (-1 == newSock)
{
// something went wrong: kill the server
perror("accept()");
break
}
else
{
// say hello
static const char hello[] = "Hello, world!\n";
int n = write(newSock, hello, sizeof hello - 1); /* -1 to exclude the final '\0' char */
if (n < 0)
perror("write");
close(newSock);
}
}
// And close the server listening socket
close(defSock);
return 0;
}
如何才能获取父级的数据值属性?
示例输出: 1,3,3
答案 0 :(得分:1)
试试这个简单的方法:
$('ol > li').not('ol ol li').attr('data-value');
或循环:
$('ol > li').not('ol ol li').each(function() {
console.log($(this).attr('data-value'));
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ol>
<li data-value="1">
<ol>
<li data-value="1a"></li>
<li data-value="2a"></li>
<li data-value="3a"></li>
</ol>
</li>
<li data-value="2"></li>
<li data-value="3"></li>
</ol>
答案 1 :(得分:0)
您可以尝试:
$(document).ready(function() {
$("ol").first().find("> li").each(function() {
console.log($(this).data("value"));
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<ol>
<li data-value="1">
<ol>
<li data-value="1"></li>
<li data-value="2"></li>
<li data-value="3"></li>
</ol>
</li>
<li data-value="3"></li>
<li data-value="3"></li>
</ol>
答案 2 :(得分:0)
答案 3 :(得分:0)
$('li').not('li ol li').each(function(){
console.log($(this).attr('data-value'))
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ol>
<li data-value="1">
<ol>
<li data-value="1"></li>
<li data-value="2"></li>
<li data-value="3"></li>
</ol>
</li>
<li data-value="3"></li>
<li data-value="3"></li>
</ol>
试试这个
答案 4 :(得分:-1)
尝试使用jQuery .parents
函数:
$(this).parents("[data-testing]:first");