簡體   English   中英

有關函數參數的Javascript元素子級

[英]Javascript element children about function parameter

以下是進行邊秀的代碼的一部分。 讓我感到困惑的是:在這種情況下,參數“容器”的等效DOM節點是什么? 有很多元素,如何考慮<img>元素是container.children?

<!DOCTYPE html>
<html>
    <head>
        <title></title>
    </head>
    <body>

    <div id="slideshow">
        <img src="https://www.kasandbox.org/programming-images/animals/birds_rainbow-lorakeets.png" alt="Rainbow lorakeets" />
        <img src="https://www.kasandbox.org/programming-images/animals/butterfly.png"alt="Butterfly" />
        <img src="https://www.kasandbox.org/programming-images/animals/cat.png" alt="Cat" />
        <img src="https://www.kasandbox.org/programming-images/animals/crocodiles.png" alt="Crocodiles" />
        <img src="https://www.kasandbox.org/programming-images/animals/fox.png" alt="Fox" />

    </div>

    <script>
var slideShow = function(container) {
    this.images = [];
    this.curImage = 0;
    for (i = 0; i < container.childElementCount; i++) {
        this.images.push(container.children[i]);
        this.images[i].style.display = "none";
    }

container是調用new slideShow()時傳遞的任何元素。 在您的情況下,應為:

var ss = new slideShow(document.getElementById('slideshow'));

然后container.children是直接嵌套在該DIV中的元素,它們都是<img>元素。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM