Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.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:数组[i].children()不是函数_Javascript_Jquery - Fatal编程技术网

Javascript jQuery:数组[i].children()不是函数

Javascript jQuery:数组[i].children()不是函数,javascript,jquery,Javascript,Jquery,以下代码的灵感来自:将光标移动到脚注符号上时,脚注将显示为工具提示 <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>footnote demo</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"&

以下代码的灵感来自:将光标移动到脚注符号上时,脚注将显示为工具提示

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>footnote demo</title>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
</head>
<body>

<p>Baryonyx was a theropod dinosaur of the early Cretaceous Period, about 130–125 million years ago<a href="#fn1" class="footnoteRef" id="fnref1"><sup>1</sup></a>. An identifying specimen of the genus was discovered in 1983 in Surrey, England; fragmentary specimens<a href="#fn2" class="footnoteRef" id="fnref2"><sup>2</sup></a> were later discovered in other parts of the United Kingdom and Iberia. Meaning "heavy claw", Baryonyx refers to the animal's very large claw (31 cm or 12 in) on the first finger. The 1983 specimen<a href="#fn3" class="footnoteRef" id="fnref3"><sup>3</sup></a> is one of the most complete theropod skeletons from the UK, and its discovery attracted media attention.</p>

<div class="footnotes">
<hr>
<ol>
<li id="fn1"><p>Baryonyx caught and held its prey primarily with its strong forelimbs and large claws.<a href="#fnref1">↩</a></p></li>
<li id="fn2"><p>The creature lived near bodies of water, in areas where other theropod, ornithopod, and sauropod dinosaurs have also been found. <a href="#fnref2">↩</a></p></li>
<li id="fn3"><p>It had a long, low, bulbous snout and narrow, many-toothed jaws, which have been compared to gharial jaws.<a href="#fnref3">↩</a></p></li>
</ol>
</div>

<script>
var removeElements = function(text, selector) {
    var wrapped = $("<div>" + text + "</div>");
    wrapped.find(selector).remove();
    return wrapped.html();
}

var $fRef = $(".footnoteRef");
for(var i=0; i<$fRef.length; i++) {
    var sup = $fRef.children("sup")[i];
    //var sup = $fRef[i].children("sup");
    //var sup = $fRef.eq(i).children("sup");
    //var sup = $fRef.get(i).children("sup");
    //var sup = $($fRef[i]).children("sup");
    //debugger;
    sup.setAttribute('fnID',i);
    sup.onmouseover = function(event) {
        var fnTip = document.getElementById('fnTip');
        if(fnTip) fnTip.parentNode.removeChild(fnTip);
        var pTip = document.createElement('div');
        var fnT = document.getElementById($fRef[this.getAttribute('fnID')].getAttribute("href").substring(1)).innerHTML;
        pTip.innerHTML = removeElements(fnT,"a");
        pTip.id = 'fnTip';
        pTip.style.position = 'absolute';
        pTip.style.left = (event.pageX - 180) + 'px';
        pTip.style.top = (event.pageY + 20) + 'px';
        pTip.style.width = '360px';
        pTip.style.textIndent = '2em';
        pTip.style.textAlign = 'left';
        pTip.style.backgroundColor = '#FFFFE0';
        pTip.style.border = '1px solid #636363';
        pTip.style.padding = '5px';
        pTip.style.fontSize = '12px';
        pTip.style.lineHeight = '1.8';
        pTip.style.borderRadius =  '5px';
        document.body.appendChild(pTip);
    };

    sup.onmouseout = function(event) {
        var fnTip = document.getElementById('fnTip');
        if(fnTip) fnTip.parentNode.removeChild(fnTip);
    };
}

</script>

</body>
</html>

脚注演示
重子是白垩纪早期的兽脚类恐龙,大约1.3亿到1.25亿年前。1983年在英国萨里发现了该属的鉴定标本;后来在英国和伊比利亚的其他地方发现了碎片标本。重子的意思是“重爪”,是指动物在第一个手指上非常大的爪(31厘米或12英寸)。1983年的标本是英国最完整的兽脚类骨骼之一,它的发现引起了媒体的关注


  • 重子鸟主要用强壮的前肢和大爪子捕捉并抓住猎物

  • 这种生物生活在水体附近,在那里还发现了其他兽脚类、鸟脚类和蜥脚类恐龙

  • 它有一个长、低、球状的口鼻和狭窄、多齿的下颚,这被比作gharial下颚

  • var removeElements=函数(文本、选择器){ var wrapped=$(“”+text+“”); wrapped.find(选择器).remove(); 返回wrapped.html(); } var$fRef=$(“.footnoteRef”); 对于(var i=0;i
  • var sup=$fRef.children(“sup”)[i];

    获取$fRef子元素集合中的第i个元素;
    所有其他方法都处理$fRef集合的第i个元素:

  • var-sup=$fRef[i].儿童(“sup”);

    尝试在jQuery集合$fRef的第i个元素上调用函数children,但该元素是经典的Dom元素,因此它没有任何children方法

  • var sup=$fRef.eq(i).children(“sup”);

    执行与2相同的操作,但正确,因为eq将返回一个jQuery对象。它检索$rFref第i个元素的所有子元素

  • var sup=$fRef.get(i).children(“sup”);

    get方法的作用与index相同:它获取dom对象,因此也不起作用

  • var sup=$($fRef[i])。子项(“sup”);

    当您在dom元素中重写html集合时,它也将起到3的作用


  • 由于jQuery
    .children()的
    方法将把所有匹配元素的所有子元素收集到一个集合中,因此您正在获取该集合中的
    i
    。因此,只要每个
    footnotRef
    中只有一个
    sup
    ,它就可以可靠地工作。您的标题和代码不匹配…对不起,我对JS知之甚少,您有何建议如果可能,我将编辑标题。