ボタンA〜Zが表示されるjqueryループがありますが、それは行の7つのボタンを表示します。だから、以下のようになります。最後の行のボタンがありません
A B C D E F G
H I J K L M N
O P Q R S T U
V W X Y Z
しかし、問題は、このループは、各行の最後のボタンが不足していることが原因とされていることです。ボタンG、N、Uはありません。私はなぜ彼らが行方不明であるか、これらのボタンと他のボタンを表示するために、以下のコードを修正する方法を知りたい。
var i = 1;
$('#optionAndAnswer .answers').each(function() {
var $this = $(this);
var $newBtn = '';
if($this.is(':visible')){
$newBtn = $("<input class='answerBtnsRow answers' type='button' style='display: inline-block;' onclick='btnclick(this);' />").attr('name', $this.attr('name')).attr('value', $this.val()).attr('class', $this.attr('class'));
}else{
$newBtn = $("<input class='answerBtnsRow answers' type='button' style='display: none;' onclick='btnclick(this);' />").attr('name', $this.attr('name')).attr('value', $this.val()).attr('class', $this.attr('class'));
}
if(i % 7 == 0){
$answer.append($newBtn+"<tr></tr>");
}
else
$answer.append($newBtn);
i = i+1;
});
PHP CODE:
<?php
$a = range("A","Z");
?>
<table>
<tr>
<?php
$i = 1;
foreach($a as $key => $val){
if($i%7 == 1) echo"<tr><td>";
echo"<input type=\"button\" onclick=\"btnclick(this);\" value=\"$val\" id=\"answer".$val."\" name=\"answer".$val."Name\" class=\"answerBtns answers answerBtnsOff\" style=\"display: inline;\">";
if($i%7 == 0) echo"</td></tr>";
$i++;
}
?>
</tr>
</table>
あなたのHTMLせずに言うのは難しいが'var i = 0'? –
もし私が(i%8 === 0) – BruceyBandit
@ T.J.の場合、これを行うと、H、P、Xという文字が欠けています。私は空の行を追加したい – BruceyBandit