Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.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如何选择动态创建的所有音频元素?_Javascript_Jquery_Html_Selector - Fatal编程技术网

JavaScript/jQuery如何选择动态创建的所有音频元素?

JavaScript/jQuery如何选择动态创建的所有音频元素?,javascript,jquery,html,selector,Javascript,Jquery,Html,Selector,我是通过document.ready中的javascript创建元素的 如何选择我创建的所有元素?我在任何地方都找不到一个简单/有效的答案 这是我试过的,但不起作用 $(document).ready(function () { $.audioElement1 = document.createElement('audio'); $.audioElement1.setAttribute('src', '/Content/mfile1.mp3'); $.audioElement2 = docu

我是通过document.ready中的javascript创建元素的

如何选择我创建的所有元素?我在任何地方都找不到一个简单/有效的答案

这是我试过的,但不起作用

$(document).ready(function () {

$.audioElement1 = document.createElement('audio');
$.audioElement1.setAttribute('src', '/Content/mfile1.mp3');

$.audioElement2 = document.createElement('audio');
$.audioElement2.setAttribute('src', '/Content/mfile2.mp3');

});



function stopAll()
        {
            var cnt = 0;
            $("audio").each(function () {
                cnt += 1;
                this.pause(); // Stop playing
                this.currentTime = 0; // Reset time
            });

            alert("total: " + cnt);
        }

我的“警报”每次返回0/不执行任何操作

您可以使用
document.getElementsByTagName('audio')
而不是
$(“audio”)

它返回所有音频元素的数组


您尚未将这些音频添加到文档中。您是正确的,但是。。。。。。难道我不是通过javascript添加的吗!?