最近の更新

2012年9月7日金曜日

テーブルのセルの間隔を変更する方法(HTMLのcellspacing属性)

【目的】
jQueryで、HTMLのテーブルのセルの余白をHTMLのcellspacing属性で変更します。



【手順】
1.「jQuery1.8.1のダウンロード方法」の手順で、jQuery1.8.1をダウンロードしておきます。
2.「006-TableCellSpacingJQuery.html」というファイルを作成。
3.「006-TableCellSpacingJQuery.html」を以下の様に入力。
<html>
<head>
    <script type="text/javascript" src="./jquery-1.8.1.min.js"></script>
    <script type="text/javascript">
    $(function(){
        $("#button1").click(function(){
            $("#table1").attr("cellSpacing", parseInt($("#table1").attr("cellSpacing"))+1);
        })
        $("#button2").click(function(){
            $("#table1").attr("cellSpacing", parseInt($("#table1").attr("cellSpacing"))-1);
        })
    })
    </script>
</head>
<body>
    <table id="table1" border="1" cellspacing="10">
        <tr>
            <td>セル1-1</td>
            <td>セル1-2</td>
        </tr>
        <tr>
            <td>セル2-1</td>
            <td>セル2-2</td>
        </tr>
    </table>
    <input id="button1" type="button" value="+">
    <input id="button2" type="button" value="-">
</body>
</html>

4.ダウンロードした「jquery-1.8.1.min.js」と「006-TableCellSpacingJQuery.html」を同一ディレクトリに配置します。
5.「006-TableCellSpacingJQuery.html」をブラウザで開きます。
6.以下の様に表示されれば成功です。












































以上です。

0 件のコメント:

コメントを投稿

注: コメントを投稿できるのは、このブログのメンバーだけです。

関連記事