我有5個div標籤和5個html輸入按鈕,我想用html輸入按鈕單擊一次選擇/顯示一個div。如何使用html輸入button1顯示一個div1 div2 div3 div4 div5 button2 button3 button4 button5
<script>
$(function() {
// Store our questions in a variable
var $questions = $('.question');
// Show the first question
$questions.first().show();
// When clicking the <button> in ny of the questions...
$questions.find('input').on('click', function() {
// ...store the currently visible question, then...
var $visibleQuestion = $questions.filter(':visible');
// ...if there's a next question....
var $nextQuestion = $visibleQuestion.next('.question');
console.log($nextQuestion);
if ($nextQuestion.length === 1) {
// ...hide the visible question....
$visibleQuestion.hide();
// ..and show the next.
$nextQuestion.show();
}
// If you want, you can check for quiz completition in this else section
else {
// Quiz finished
alert('You finished the quiz!');
}
});
// Optionally, change the text of the last question's button
$questions.last().find('input').text('Finish Quiz');
});
</script>
<script type="text/javascript">
var x, y;
var i = 0;
var j = 0;
for (x = 0; x < 20; x++) {
for (y = 0; y < 5; y = y + 1) {
document.write('<input id="button' + (i + 1) + '" class="btnClass" type="button" value="' + (i + 1) + '" style="width:30px; height:25px;text-align:left;" />');
i++;
document.write('   ');
if (i % 5 == 0) {
document.write('<br /> <br />');
}
}
}
</script>
你到目前爲止嘗試過什麼?請編輯您的問題,並將相關源代碼添加到您的問題以及迄今爲止所做的任何嘗試。謝謝。 – NewToJS
你是否嘗試過任何東西?如果是,請添加html + css(如果有的話)+最重要的是您嘗試的努力。這很好,它沒有奏效。我們將檢查並嘗試糾正它 –
我創建了100個按鈕,但我不知道如何使用這些按鈕做div操作 –