現在、各タブに1つの質問を表示するスキルテストプロジェクトに取り組んでいます。どのようにデフォルトのアクティブなタブを設定できますか?私はフォームw3schools.comをコピーした既定の開いているタブのコードがありますが、それは動作しません。なぜ私は考えていない。私は誰かが私のコードを修正するのを手伝ってくれることを願っています。どうもありがとうございます!htmlの既定のアクティブな/開いているタブを設定する方法
スタイル:
.button {
display: inline-block;
margin: 4px 2px;
border-radius: 8px;
}
div.tab {
overflow: hidden;
border: 1px solid #ccc;
background-color: #f1f1f1;
}
div.tab button {
background-color: inherit;
float: left;
border: 1px solid #ccc;
outline: none;
cursor: pointer;
padding: 13px 12.62px;
transition: 0.3s;
font-size: 10px;
}
div.tab button:hover {
background-color: #ddd;
}
div.tab button.active {
background-color: #d6f5d6;
}
.tabcontent {
display: none;
border: 1px solid #ccc;
border-top: none;
}
ボディ:
<div class="col-md-auto col-md-offset-1 col-centered">
<div class="panel panel-success">
<script>
function openTab(evt, tabName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(tabName).style.display = "block";
evt.currentTarget.className += " active";
}
document.getElementById("defaultOpen").click();
</script>
<div class="tab">
<button class="tablinks" type="button" onclick="openTab(event, 'q1')" id="defaultOpen"></button>
<button class="tablinks" type="button" onclick="openTab(event, 'q2')"></button>
<button class="tablinks" type="button" onclick="openTab(event, 'q3')"></button>
<?php if (mysqli_num_rows($result) > 0): ?>
<?php $index = 0; $num=0; ?>
<div id="q<?php echo ($index++); ?>" class="tabcontent">
<table class="table table-hover">
<tbody>
<tr class="form-group">
<h3 name="ques[<?php echo $test_id;?>]" style="text-indent: 40px;"> <?php echo $num,'. ', $question; ?> </h3>
</tr>
<tr class="form-group">
<label class="radio-inline" style="text-indent: 70px; font-size: 18px;">
<input style="font-size: 18px;" type="radio" name="ans[<?php echo $test_id;?>]" value="<?php echo $optiona;?>"><?php echo $optiona;?>
</label>
<br>
<label class="radio-inline" style="text-indent: 70px; font-size: 18px;">
<input style="font-size: 18px;" type="radio" name="ans[<?php echo $test_id;?>]" value="<?php echo $optionb;?>"><?php echo $optionb; ?>
</label>
<br>
<label class="radio-inline" style="text-indent: 70px; font-size: 18px;">
<input style="font-size: 18px;" type="radio" name="ans[<?php echo $test_id;?>]" value="<?php echo $optionc;?>"><?php echo $optionc;?>
</label>
<br>
</tr>
</tbody>
</table>
<br>
</div>
<?php $num++; ?>
<?php endif ?>
</form>
</div>
</div>
</div>
私はPHPを知らないが、あなたはありませんforeachのとendforeachを持っています。 –
ああ、私はそれらが重要であるか私の質問に関係していないので、私のコードのいくつかの部分を含んでいませんでした。 – Dza