2015-04-25 61 views
1

我正在嘗試爲用戶創建一個開放環境來選擇特定的選項,但同時給他們提供了以任何順序選擇它們的機會,但是卻沒有選擇他們選擇了。到目前爲止,我的代碼在按順序執行時停止了我的工作。基本上,選擇和選項在一個範圍內彈出。他們選擇一個。結果會在該範圍內傳遞,同樣的選項似乎還沒有消除他們已經選擇的選項。根據用戶的決定禁用選定的選項

這裏的HTML代碼

<div><select id="lies"> 
<option value="" selected='selected'>Select a lie...</option> 
<option value="FBI">We're undercover agents</option> 
<option value="super">We're superheroes</option> 
<option value="confess">We're the bombers</option> 
</select></div> 

<span id='FBI'> 
<p>"We're undercover students working with the FBI," you say.</p> 
<p>"Get outta here before I put you both in cuffs!" he yells.</p> 
<p>"Good job, <?php echo $_GET['Name']?>! You almost got us busted.." </p> 
<p>"Come on, Korra, let's try one more! Over there!" you exclaim.</p> 
<div><select id="lies"> 
<option value="" selected='selected'>Select a lie...</option> 
<option value="FBI">We're undercover agents</option> 
<option value="super">We're superheroes</option> 
<option value="confess">We're the bombers</option> 
</select></div> 
</span> 

<span id='super'> 
<p>"Let us through, we're bulletproof!" you fearlessly say.</p> 
<p>"Are ya now?" asks the cop as he lightly bops you over the head with his fist.</p> 
<p>"OW!" you yell.</p> 
<p>"Run along and go play somewhere else, stupid kid!"</p> 
<p>You and Korra walk away feeling defeated.</p> 
<p>"Any other ideas, <?php echo $_GET['Name']?>?" she asks.</p> 
<p>"One more try!" you say as you run over to another police officer.</p> 
<div><select id="lies"> 
<option value="" selected='selected'>Select a lie...</option> 
<option value="FBI">We're undercover agents</option> 
<option value="super">We're superheroes</option> 
<option value="confess">We're the bombers</option> 
</select></div> 
</span> 

<span id='confess'> 
<p>"It was us!"</p> 
<p>"Alright off to jail you go!" says the officer.</p> 
You get escorted off to jail. THE END. 
</span> 

,這裏是jQuery的

//Keeps the spans containing the respondes hidden until an option is selected for the lietocops page 

$('#lies').change(function(){ 
var contact = $(this).val(); 

// Hides the list/show list 

if (contact == ""){ 
$('#lies').show(); 
}else{ 
$('#lies').hide(); 
} 

$("#lies option:selected").attr('disabled','disabled') 
    .siblings().removeAttr('disabled'); 

// lie responses 

if(contact == "FBI") { 
$('#FBI').fadeIn(); 
}else if(contact == "super") { 
$('#super').fadeIn(); 
}else if(contact == "confess") { 
$('#confess').fadeIn(); 
} 
}); 
+0

我不知道看什麼你想在這裏做,你可以重新制定該好嗎? – sebastienbarbier

+0

用戶可以從列表中選擇一個選項。 選項a,b或c。 用戶選擇一個選項。故事通過執行特定的跨度繼續執行所選擇的選項,並給予另一組選項,同時消除已選擇的選項。我希望能夠以任何順序執行代碼。 –

+0

即時通訊工作在互動小說 –

回答

0

首先,你有多個ID的一個問題,這是不允許的。你需要讓他們上課。

並給你的故事情節一個類(ex故事情節)。因此,對選擇什麼

var $lies = $(".lies"); 
$lies.change(function(){ 
$("#firstLie").hide(); 
var $this = $(this); 
var contact = $this.val(); 
var $currentStoryline = $this.closest(".storyline"); 
var $selectedOptions = $(".lies").find("option[value='" + contact + "']"); 
$selectedOptions.prop("disabled", true);  
$lies.val(""); 
$currentStoryline.fadeOut(); 
$("#" + contact).fadeIn(); 
+0

所以在這種情況下,我不得不改變ID爲類?並添加該代碼的其餘部分? –

+0

是剛剛測試。你可以在這裏看到它的行動: http://elveneleven.com/test.html ,因此,如果有什麼不明確,從該頁面獲得所需的一切。 –

+0

不錯!我是否需要從當前的代碼中刪除任何內容?除了將ID更改爲類。我應該在哪裏實現你的代碼? –

相關問題