<legend id='f51i0'><style id='f51i0'><dir id='f51i0'><q id='f51i0'></q></dir></style></legend>

    <i id='f51i0'><tr id='f51i0'><dt id='f51i0'><q id='f51i0'><span id='f51i0'><b id='f51i0'><form id='f51i0'><ins id='f51i0'></ins><ul id='f51i0'></ul><sub id='f51i0'></sub></form><legend id='f51i0'></legend><bdo id='f51i0'><pre id='f51i0'><center id='f51i0'></center></pre></bdo></b><th id='f51i0'></th></span></q></dt></tr></i><div id='f51i0'><tfoot id='f51i0'></tfoot><dl id='f51i0'><fieldset id='f51i0'></fieldset></dl></div>
      <tfoot id='f51i0'></tfoot>
        <bdo id='f51i0'></bdo><ul id='f51i0'></ul>

      <small id='f51i0'></small><noframes id='f51i0'>

      在javascript中将事件侦听器添加到音频HTML5标签

      时间:2023-09-04

      1. <small id='x6jbU'></small><noframes id='x6jbU'>

        <legend id='x6jbU'><style id='x6jbU'><dir id='x6jbU'><q id='x6jbU'></q></dir></style></legend>
      2. <tfoot id='x6jbU'></tfoot>
          <i id='x6jbU'><tr id='x6jbU'><dt id='x6jbU'><q id='x6jbU'><span id='x6jbU'><b id='x6jbU'><form id='x6jbU'><ins id='x6jbU'></ins><ul id='x6jbU'></ul><sub id='x6jbU'></sub></form><legend id='x6jbU'></legend><bdo id='x6jbU'><pre id='x6jbU'><center id='x6jbU'></center></pre></bdo></b><th id='x6jbU'></th></span></q></dt></tr></i><div id='x6jbU'><tfoot id='x6jbU'></tfoot><dl id='x6jbU'><fieldset id='x6jbU'></fieldset></dl></div>
              <tbody id='x6jbU'></tbody>

              • <bdo id='x6jbU'></bdo><ul id='x6jbU'></ul>
                本文介绍了在javascript中将事件侦听器添加到音频HTML5标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                您好,我正在 Javascript 中创建一个新的音频标签元素,代码如下:

                Hi I'm creating a new audio tag element in Javascript this is the code:

                var audio = document.createElement("audio");
                audio.setAttribute("id","myid");
                audio.setAttribute("autoplay","autoplay");
                document.body.appendChild(audio);
                

                在将它附加到正文之前,我想放置一个 onended 事件处理程序,我尝试过这样的事情:

                before appending it to the body, I'd like to place an onended event handler, I tried something like this:

                audio.onended = foo;
                

                其中 foo 类似于:function foo(){alert('Hola')}

                where foo is something like: function foo(){alert('Hola')}

                audio.setAttribute("onended","foo()");
                

                在这两种情况下它都不起作用.在第一种情况下,音频标签是在没有任何 onended 事件处理程序的情况下附加的;而在第二种情况下,附加了音频标签,onended 事件在属性上,但它不会触发.

                in both case it didn't work. In the first case the audio tag is appended without any onended event handler; while in the second case the audio tag is appended, the onended event is on the attributes but it does not fire.

                有人知道吗?

                提前致谢.

                -z-

                推荐答案

                试试:

                audio.addEventListener('ended', foo);
                

                这是添加事件监听器的正确标准方法.

                This is the correct and standard method to add event listeners.

                这篇关于在javascript中将事件侦听器添加到音频HTML5标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:Backbone.js:如何从事件中解除绑定,模型移除 下一篇:处理浏览器的“ctrl+s"按键事件

                相关文章

                最新文章

                • <bdo id='Dmd2N'></bdo><ul id='Dmd2N'></ul>
              • <tfoot id='Dmd2N'></tfoot>
                  <i id='Dmd2N'><tr id='Dmd2N'><dt id='Dmd2N'><q id='Dmd2N'><span id='Dmd2N'><b id='Dmd2N'><form id='Dmd2N'><ins id='Dmd2N'></ins><ul id='Dmd2N'></ul><sub id='Dmd2N'></sub></form><legend id='Dmd2N'></legend><bdo id='Dmd2N'><pre id='Dmd2N'><center id='Dmd2N'></center></pre></bdo></b><th id='Dmd2N'></th></span></q></dt></tr></i><div id='Dmd2N'><tfoot id='Dmd2N'></tfoot><dl id='Dmd2N'><fieldset id='Dmd2N'></fieldset></dl></div>

                  1. <small id='Dmd2N'></small><noframes id='Dmd2N'>

                    <legend id='Dmd2N'><style id='Dmd2N'><dir id='Dmd2N'><q id='Dmd2N'></q></dir></style></legend>