1
我正在使用jQuery-SlotMachine,特別是隨機函數發生器。這是我的HTML:在jQuery老虎機中顯示活動元素的文本內容
<div id="machine1">
<span class="option">
<span>Example A</span>
<span>Example B</span>
</span>
</div>
<div id="machine2">
<span class="option">
<span>Example C</span>
<span>Example D</span>
</span>
</div>
<div id="results">
<span></span>
</div>
這裏是我的JS:
var machine1 = $("#machine1").slotMachine({
active : 0,
delay : 500
});
var machine2 = $("#machine2").slotMachine({
active : 1,
delay : 500,
direction: 'down'
});
function onComplete(active){
switch(this.element[0].id){
case 'machine1':
$("#machine1Result").text(this.active);
break;
case 'machine2':
$("#machine2Result").text(this.active);
break;
}
}
$("#randomizeButton").click(function(){
machine1.shuffle(5, onComplete);
setTimeout(function(){
machine2.shuffle(5, onComplete);
}, 500);
});
所以我想要做的就是吐出名爲「結果」的容器的結果。我知道this.active給了我當前元素的索引號,但是我想要顯示的是文本值。所以我想表現出像「例子B例子C」。我試過使用像var $ results = $('。active')這樣的東西。與$('#results')。html($ results);但jQuery不是我的強項。
嗯,非常感謝你的建議。我一直在玩這個。似乎無法得到它的工作。我在這裏製作了一個[codepen](https://codepen.io/simonfoust/pen/LzVEEZ?editors=1010#0)。 – simonfoust
請參閱我編輯的解決方案。棘手。 – PerpetualStudent
我在你的債務。 :) – simonfoust