-1

私のコード

HTML

<div style="position:relative;">
    <div class="boxImmagineResultNext"></div>
    <div class="boxImmagineResult">                
        <textarea cols="15" rows="5"></textarea>
    </div>
</div> 

CSS

.boxImmagineResultNext
{
    height: 235px;
    position: relative;
    width: 200px;
    z-index: 1;
    display:none;    
}

.boxImmagineResult
{
    background-color: #595959;
    height: 255px;
    position: relative;
    width: 220px;
    z-index: 1;
    top:0;
    left:0;
}
​

jQuery

$('.boxImmagineResult').mousedown(function (e) {
    $(this).css({ 'position': 'absolute', 'z-index': '10' });
    $('.boxImmagineResultNext').show();
});


$('.boxImmagineResult').mouseup(function (e) {
    $(this).css({ 'position': 'relative', 'z-index': '5' });
    $('.boxImmagineResultNext').hide();
});​

このメカニズムのため、テキストエリアに「書き込む」ことができません。これはFirefoxだけで、たとえばChromeでも同様に機能します。「読み取り専用」のように見えますが、実際はそうではありません。

どうすれば修正できますか?テキストエリアをクリックするときは、マウスダウンを「避ける」必要があります...

4

1 に答える 1

1

イベント委任を使用すると、ターゲット(イベントを開始した要素)が何であるか、またはトリガーにしたいものではないかをテストできるため、役立つ場合があります。

$('.boxImmagineResult').on('mousedown', function(e){
    var $target = $(e.target);
    if( $target.is('SELECTOR') ){
        // Do stuff here ...
    }
    return false;
});
于 2012-09-21T15:43:32.133 に答える