0

いくつかの情報を表示するテーブルがあります。私が達成したいのは、ユーザーが行をクリックして、その行の情報に関連するメモをその行の下に表示できるようにすることです。

気の利いたCSSトランジション機能を使用できるように設定しようとしているので、情報行の下の非表示の絶対位置の行にメモを配置するだけでは問題ありません。CSSトランジションはpositionスタイルに影響しません。

メモがに入るように設定しましたdiv。ユーザーがテーブルの行をクリックすると、onClickイベントがJavascript関数を呼び出してdiv表示します。必要なのは、選択したテーブル行の下にdivを並べるだけです。

テーブル行の高さと位置を取得するにはどうすればよいですか?私はそれを使ってを配置できると思いますdiv。または、これを行うためのより良い方法はありますか?

これが私が持っているものの例です:

<style>
    .emarNote{
                transition: all .3s linear;
                -o-transition: all .3s linear;
                -moz-transition: all .3s linear;
                -webkit-transition: all .3s linear;
            }
</style>

<script type="text/javascript">
    function showEmar(id)
    {
        if (document.getElementById("emarNote"+id).style.visibility == "hidden")
        {
            document.getElementById("emarNote"+id).style.visibility = 'visible';
            document.getElementById("emarNote"+id).style.opacity = 1;
        }
        else
        {
            document.getElementById("emarNote"+id).style.opacity = 0;
            document.getElementById("emarNote"+id).style.visibility = 'hidden';
        }
    }
</script>

<table>
    <tr onClick="showEmar(1)">
        <td>Info</td>
        <td>Info</td>
    </tr>
</table>

<div id="emar1" class="emarNote" style="visibility:hidden; opacity:0; position:absolute;">
    note about info
</div>
4

1 に答える 1

0

最初にJQueryをダウンロードします。次に、以下のようにします。

    <style>
    .emarNote{ background:#CCCCCC; }        
</style>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $('.emarNote').hide();
    $('tbody', '#myTable').click(function(event) {
        tr_ID = $(event.target).parent().attr('id');
        $('#' + tr_ID + '-info').fadeToggle('slow');
    });
});
</script>

<table id="myTable">
<tbody>
    <tr id="row1">
        <td>Info</td>
        <td>Info</td>
    </tr>
    <tr>
    <td colspan="2" id="row1-info" class="emarNote">MORE INFO would be really cool and such</td>
    </tr>
    </tbody>
</table>

注: スライド効果を実現するには、「fadeToggle」を「slideToggle」に置き換えます。また、ソリューションを完全に理解するには、JQuery について少し読む必要があると思います。基本を理解すれば、実際には非常に簡単に理解できることがわかります。

于 2010-12-09T02:07:22.540 に答える