JavaScript   发布时间:2022-04-16  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了javascript – 检测父母是可容忍div的可内容小孩的keyup事件大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
目标:将keydown事件处理程序附加到作为可填写div的子代的可满足范围.

问题:如果您输入跨度,父事件不会被触发.我想要的是孩子触发,@R_743_9447@抓住文本.我只想要这个可爱的孩子,因为会有很多.

HTML / JS在下面,小提琴链接在这里:http://jsfiddle.net/aBYpt/4/

HTML

<div class="parent" contenteditable="true">
    Parent div text.

    <span class="child" contenteditable="true">First child span text.</span>
    <span class="child" contenteditable="true">Second child span text.</span>
    <span class="child" contenteditable="true">Third child span text.</span>
</div>

<div id="console"></div>

的JavaScript / jQuery的

$(document).on( 'keyup','.parent',function() {
    $('#console').html( 'Parent keyup event fired.' );
    //do stuff
});

$(document).on( 'keyup','.child',function() {
    $('#console').html( 'Child keyup event fired.' );
    //do stuff
});

**注意:事件处理被委派为文档,因为元素被动态添加.

解决方法

所以这是一个bug.解决方法确认FF23和CHROME29(在没有vm的linux上,所以不能测试IE).您必须将包装跨度设置为contenteditable false,您不能仅仅省略声明contenteditable属性,这是非常可靠的.解决方案通过 Keypress event on nested content editable (jQuery)

这是小提琴:http://jsfiddle.net/aBYpt/14/

HTML

<div class="parent" contenteditable="true">
    Parent div text.

    <span contenteditable="false">
        <span class="child" contenteditable="true">First child span text.</span>
    <span contenteditable="false">
        <span class="child" contenteditable="true">Second child span text.</span>
    </span>
</div>

<div id="console"></div>

的JavaScript / jQuery的

$(document).on( 'keyup',function() {
    //do stuff
    $('#console').html( 'Parent keyup event fired.' );
});

$(document).on( 'keyup',function(E) {
    //do stuff
    $('#console').html( 'Child keyup event fired.' );
    e.stopPropagation();
});

大佬总结

以上是大佬教程为你收集整理的javascript – 检测父母是可容忍div的可内容小孩的keyup事件全部内容,希望文章能够帮你解决javascript – 检测父母是可容忍div的可内容小孩的keyup事件所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。