小编scr*_*agz的帖子

修改尚未创建的元素的首选方法(除了事件)

关于将未来的操作绑定到不存在的元素存在很多问题,这些元素最终都以live/delegate回答.我想知道如何运行任意回调(例如,添加类或触发插件)匹配选择器的所有现有元素以及与尚未创建的相同选择器匹配的所有未来元素.

似乎livequery插件的主要功能使其成为核心,但另一部分,附加任意回调在某种程度上丢失了.

另一个常见的答案是事件委派,但是如果一个人无法访问创建元素以触发事件的所有供应商代码,该怎么办?


这是一些现实世界的代码:

// with livequery
$('input[type=text], input[type=password], textarea, .basic_form .block select, .order_form .form_item select, .order_form .form_item input')
    .livequery(function(){
        $(this)
            .focus(function(){
                $(this).addClass('active');
            })
            .blur(function(){
                $(this).removeClass('active');
            })
            .addClass('text');
    });

// with live
$('input[type=text], input[type=password], textarea, .basic_form .block select, .order_form .form_item select, .order_form .form_item input')
    .live('focus', function(){
            $(this).addClass('active');
        })
    .live('blur', function(){
            $(this).removeClass('active');
        });
    // now how to add the class to future …
Run Code Online (Sandbox Code Playgroud)

javascript jquery events mutation-events

42
推荐指数
2
解决办法
2300
查看次数

HTML5语义线程评论

在HTML5中处理博客上的线程评论时,你会期望评论的线程是嵌套<article>的吗?或者您是否会认为嵌套的评论只是<article>博客文章范围内的另一个,并且线程是显示问题?

例A:

<section>
<article>
...blog post...
<section id="comments">
<article id="comment_1">...comment 1...</article>
<article id="comment_2">
   ...comment 2...
   <article id="comment_3">...comment 3 in response to comment 2...</article>
   <article id="comment_4">
       ...comment 4 in response to comment 2...
       <article id="comment_4">...comment 5 in response to comment 4...</article>
   </article>
</article>
<article id="comment_6">...comment 6...</article>
</section>
</article>
</section>
Run Code Online (Sandbox Code Playgroud)

例B(理论上的rel ="parent"):

<section>
<article>
...blog post...
<section id="comments">
<article id="comment_1">...comment 1...</article>
<article id="comment_2">...comment 2...</article>
<article id="comment_3" rel="comment_2" class="indent-1">...comment 3 in response to comment 2...</article>
<article id="comment_4" rel="comment_2" class="indent-1">...comment …
Run Code Online (Sandbox Code Playgroud)

html5 semantics

11
推荐指数
1
解决办法
1411
查看次数

标签 统计

events ×1

html5 ×1

javascript ×1

jquery ×1

mutation-events ×1

semantics ×1