1
<div id="theHover" class="therequest" style="display:none;">

<div class="noprint"><button  id="closetheHover">Close Window</button></div>

All My Content

<div class="noprint"><button id="theprint" class="print">Print</button></div>

</div>

印刷ボタン以外のdivのどこかをクリックしたときにホバーdivを閉じたい

ボタンを閉じると、ホバーが閉じます。

$("#closetheHover").live("click", function(){  
 $("#theHover").hide();
 });
4

2 に答える 2

3
$(document).on("click", "#closetheHover", function(e){  
    if (e.target.id != 'theprint') {
        $("#theHover").hide();
    }
});​

document最も近い非動的な親に置き換えてください!

于 2012-04-26T14:36:23.707 に答える
1

私はお勧めします:

$("#theHover").on("click", '*:not("#thePrint")', function(){  
    $("#theHover").hide();
});

JS Fiddle の概念実証

注意してくださいlive()。jQuery 1.7 で非推奨になりました。1.7より前のバージョンを使用している場合、API は を使用することを推奨してdelegate()おり、 1.7 以降では を使用することを推奨していますon()

参考文献:

于 2012-04-26T14:35:59.677 に答える