简体   繁体   English

jquery:绘制和擦除焦点上的边框,并在div的任何子元素上模糊

[英]jquery: drawing and erasing border on focus and blur on any child elements of a div

I'm having a div which can have many (not less then 5) child elements (mostly they are div , table and img ). 我有一个div,可以有很多(不少于5个)子元素(大多数是divtableimg )。 I want to draw border (eg with jquery.css method) when a user clicked on any child element of that div. 我想在用户点击该div的任何子元素时绘制边框(例如,使用jquery.css方法)。 It can be easily done with something like 可以通过类似的方式轻松完成

$div.click(function() {
    //drawing frame here
});

Removing frame on click outside is much more harder. 在外面点击移除框架要困难得多。 Of cause I can handle deselecting on click event thrown by any other div or body. 因为我可以处理任何其他div或body抛出的click事件的deselecting。 But... maybe there's more elegant solution? 但是......也许有更优雅的解决方案?

Thank you in advance! 先感谢您!

Try to use .on('focusin') and .on('focusout') events to handle that. 尝试使用.on('focusin').on('focusout')事件来处理它。

More info: focusin , focusout and .on() ; 更多信息: focusinfocusout.on() ;

Try using function on the surrounding div 尝试在周围的div 使用函数

Example: HTML: 示例:HTML:

<div id="test">
    <div><p>Hallo</p></<div>
        <img src="not found" alt="not found">
    </div>

JS: JS:

$('#test').on('click', '*', function(){

    $(this).css('border', '1px solid red');
return false;
});

Fiddler: http://fiddle.jshell.net/ 提琴手: http//fiddle.jshell.net/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM