How to get video tag src using JavaScript?

前端 未结 2 1057
自闭症患者
自闭症患者 2020-12-15 12:23

I am trying to get video URL using JavaScript. Code is ...

2条回答
  •  伪装坚强ぢ
    2020-12-15 12:55

    var vids = document.getElementsByTagName('video') 
    // vids is an HTMLCollection
    for( var i = 0; i < vids.length; i++ ){ 
        console.log( vids.item(i).src )
    }
    

    Seems to work for me! Note, that turns an HTMLCollection. .length gives the length and item(i) gives the item at i.

    var vids = document.getElementsByTagName('video') 
    // vids is an HTMLCollection
    for( var i = 0; i < vids.length; i++ ){ 
        console.log( vids.item(i).src )
    }

提交回复
热议问题