jQueryで、HTMLのテーブルのセルの間隔をCSSのborder-collapse属性で変更します。
【手順】
1.「jQuery1.8.1のダウンロード方法」の手順で、jQuery1.8.1をダウンロードしておきます。
2.「008-TableCellSpacingZeroCssJQuery.html」というファイルを作成。
3.「008-TableCellSpacingZeroCssJQuery.html」を以下の様に入力。
<html>
<head>
<script type="text/javascript" src="./jquery-1.8.1.min.js"></script>
<script type="text/javascript">
$(function(){
$("#button1").click(function(){
$("#table1").css("borderCollapse", "separate");
})
$("#button2").click(function(){
$("#table1").css("borderCollapse", "collapse");
})
})
</script>
</head>
<body>
<table id="table1" style="border-collapse: separate; border-spacing:10px;">
<tr>
<td style="border:solid 1px black;">セル1-1</td>
<td style="border:solid 1px black;">セル1-2</td>
</tr>
<tr>
<td style="border:solid 1px black;">セル2-1</td>
<td style="border:solid 1px black;">セル2-2</td>
</tr>
</table>
<input id="button1" type="button" value="separate">
<input id="button2" type="button" value="collapse">
</body>
</html>
4.ダウンロードした「jquery-1.8.1.min.js」と「008-TableCellSpacingZeroCssJQuery.html」を同一ディレクトリに配置します。
5.「008-TableCellSpacingZeroCssJQuery.html」をブラウザで開きます。
6.以下の様に表示されれば成功です。
以上です。
-01.png)
0 件のコメント:
コメントを投稿
注: コメントを投稿できるのは、このブログのメンバーだけです。