【jQuery】jQueryで、隣り合うセルの色が異なる九九表を作成せよ。
1・全ての九九の計算式にセルをつける
2・答えが奇数の行には色をつける
3・CSSについては以下を使うこと
table, tr, td {
border: solid 1px;
}
td {
padding: 5px;
}
.even {
background-color: #F5F5F5;
}
<!DOCTYPE html>
<html>
<head>
<title>九九表</title>
<style>
table, tr, td {
border: solid 1px;
}
td {
padding: 5px;
}
.even {
background-color: #F5F5F5;
}
</style>
<script src="jquery-3.6.0.min.js"></script>
<script>
$(function(){
for(var j=1; j<=9; j++){
$('#table').append('<tr></tr>');
for(var i=1; i<=9; i++){
if ( i <= 9 ) {
$('tr:last-child').append('<td>' + i + '*' + j + '=' + i*j + '</td>' );
}else {
$('tr:last-child').append('<td>' + i + '*' + j + '=' + i*j + '</td>');
}
}
}
$('td:even').addClass('even');
});
</script>
</head>
<body>
<table id="table">
<caption>九九表</caption>
</table>
</body>
</html>
・補足
1・【td:even】では、0からはじまる連番でかぞえて偶数番目のtd要素がすべてマッチする。
2・【tr:last-child】では、trの子供(td)を最後に追加するってこと
Author And Source
この問題について(【jQuery】jQueryで、隣り合うセルの色が異なる九九表を作成せよ。), 我々は、より多くの情報をここで見つけました https://qiita.com/panda-chibi/items/6c684a6cfadf7fe2aab1著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .