버튼 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'? –
만약 내가 그렇게하면 문자 H, P, X가 누락됩니다 (i % 8 === 0) – BruceyBandit
@ T.J. 빈 행을 추가하고 싶습니다. – BruceyBandit