我被卡住了,需要一點幫助。新的jQuery。點擊更改後使用id顯示div
試圖顯示一個具有特定ID的div ..但id會根據點擊按鈕而改變。
什麼,我試圖完成..
- firstoption1與secondoption1會顯示一些
- firstoption1與secondoption2會顯示一些
- firstoption1與secondoption3會顯示一些
- firstoption2與secondoption1將顯示一些東西
- firstoptio N2與secondoption2會顯示一些
- firstoption2與secondoption3將顯示
現在我堅持的東西。任何幫助將非常感激!我已經張貼在這裏我的代碼,但如果你有什麼事請讓我知道..
$(document).ready(function() {
var selectedFirstOption = "firstoption1";
var selectedSecondOption = "secondoption1";
$(".optionsSets").hide();
$(".firstOptionButton").click(function() {
selectedFirstOption = $(this).attr('id');
$(".results").html("#" + selectedFirstOption + selectedSecondOption);
});
$(".secondOptionButton").click(function() {
selectedSecondOption = $(this).attr('id');
$(".results").html("#" + selectedFirstOption + selectedSecondOption);
});
});
button {
cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<ul>
<li>
<button id="firstoption1" class="firstOptionButton">First Option 1</button>
</li>
<li>
<button id="firstoption2" class="firstOptionButton">First Option 2</button>
</li>
</ul>
<ul>
<li>
<button id="secondoption1" class="secondOptionButton">Second Option 1</button>
</li>
<li>
<button id="secondoption2" class="secondOptionButton">Second Option 2</button>
</li>
<li>
<button id="secondoption3" class="secondOptionButton">Second Option 3</button>
</li>
</ul>
<div id="firstoption1secondoption1" class="optionsSets">
<p>Showing: First Option 1 + Second Option 1</p>
</div>
<div id="firstoption1secondoption2" class="optionsSets">
<p>Showing: First Option 1 + Second Option 2</p>
</div>
<div id="firstoption1secondoption3" class="optionsSets">
<p>Showing: First Option 1 + Second Option 3</p>
</div>
<div id="firstoption2secondoption1" class="optionsSets">
<p>Showing: First Option 2 + Second Option 1</p>
</div>
<div id="firstoption2secondoption2" class="optionsSets">
<p>Showing: First Option 1 + Second Option 1</p>
</div>
<div id="firstoption2secondoption3" class="optionsSets">
<p>Showing: First Option 1 + Second Option 1</p>
</div>
<div class="results">
</div>
你不需要'$(「#」+ selectedID).show();'? – Wowsk
@Wowsk很好,趕上!修復。 –
但如何與按鈕的更改工作?選項1和選項2將隨着點擊按鈕而改變... – ToniDavisJ