首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

jqeury 添加html 元素后 .click 失效有关问题

2013-04-21 
jqeury 添加html 元素后 .click 失效问题scriptfunction xxx() {var abc lih3 classgeegee3/

jqeury 添加html 元素后 .click 失效问题

  <script>
        function xxx() {
            var abc = '<li><h3 class="geegee">3</h3></li>';
            var acc = '<li><h3 class="geegee">4</h3></li>';
            output = $(abc + acc);
            $('#category').append(output);
        }
    </script>

    <script>
        $(document).ready(function() {
            $(".geegee").click(function() {
                alert("a");
            });
        });  
    </script>
<body onload="xxx();">
        <ul id="category" class="product_category">
         <li><h3 class="geegee">1</h3></li>
         <li><h3 class="geegee">2</h3></li>
        </ul>
    </div>
</body>


原本的 1,2 有 click的功能 , onload 后添加的却没有 ,click 了没反应
这是为什么呢 ?该怎么解决 ?
[解决办法]
$(".geegee").click(function() {
                alert("a");
            });

改掉
            $("#category").delegate(".geegee","click",function() {
                alert("a");
            });

能理解自己理解,不理解来问

热点排行
Bad Request.