当前位置: 代码迷 >> JavaScript >> js里的有关问题 求解
  详细解决方案

js里的有关问题 求解

热度:86   发布时间:2013-06-25 23:45:41.0
js里的问题 求解啊

   var dic=document.getElementById("ceshi1");
                        dic.innerHTML='<a href="#?w=950" id="a1" rel="MyDiv" class="poplight">哈哈</a>';


<script type="text/javascript">
    $(document).ready(function () {
        $('a.poplight[href^=#]').click(function () {
            var popID = $(this).attr('rel'); 
            var popURL = $(this).attr('href'); 
            ... ...
</script>

这样后  引用不到 这个样式

------解决方案--------------------
改成live,设置innerHTML的代码应该执行晚于$注册的DOMReady事件导致找不到对象没绑定事件

  $('a.poplight[href^=#]').live('click',function () {
            var popID = $(this).attr('rel'); 
            var popURL = $(this).attr('href'); 
            ... ...
  相关解决方案