<bdo id='PX6cB'></bdo><ul id='PX6cB'></ul>

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

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

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

        jQuery 无法访问附加元素

        时间:2023-10-20

          <legend id='1gpDh'><style id='1gpDh'><dir id='1gpDh'><q id='1gpDh'></q></dir></style></legend>
        • <tfoot id='1gpDh'></tfoot>

              <bdo id='1gpDh'></bdo><ul id='1gpDh'></ul>
                <tbody id='1gpDh'></tbody>

              <small id='1gpDh'></small><noframes id='1gpDh'>

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

                  本文介绍了jQuery 无法访问附加元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在一个函数中有这个:

                  I have this inside a function:

                  $('#users').append($("<div id='usuarios'>").text(mensaje[1][i]));
                  

                  我想为这个新的 <div> 创建一个 onclick 事件.我怎样才能做到这一点?我在函数外这样尝试:

                  I want to create an onclick event for this new <div>. How can I achieve this? I'm trying it like this outside the function:

                  $(document).ready(function(){
                  $('#usuarios').click(function() {
                          alert("click");
                      });
                  });
                  

                  但它不起作用.

                  推荐答案

                  对于 jQuery 1.7+,您可以使用 .on()

                  For jQuery 1.7+ you can attach an event handler to a parent element using .on()

                  $(document).ready(function(){
                    $('body').on('click', '#usuarios', function() {
                       alert("click");
                    });
                  });
                  

                  甚至更好:

                  $(document).ready(function(){
                    $('#users').on('click', '#usuarios', function() {
                       alert("click");
                    });
                  });
                  

                  这篇关于jQuery 无法访问附加元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:是否可以在不修改原始代码的情况下向现有的 javascript 函数添加一些代码? 下一篇:向表单添加字段(jQuery)

                  相关文章

                    <tfoot id='Nt2Y3'></tfoot>

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

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

                        <bdo id='Nt2Y3'></bdo><ul id='Nt2Y3'></ul>