我想使用jQuery制作一个简单的基于文本的游戏。有些地方,玩家可以通过按下按钮来移动(简单地显示/隐藏相应的HTML div)。虽然我可以自由地移动到位置“竞技场”并返回“位置”位置,但我无法从任何地点的“商店”位置返回,但代码对我来说确实很合适。jQuery不处理 - 一些按钮点击事件
小提琴:https://jsfiddle.net/qyg5twoL/
$(document).ready(function(){
\t var loc="house";
\t $('#house').css('display','');
\t $('#shop').css('display','none');
\t $('#arena').css('display','none');
\t $('#gt-arena').click(function(){
\t \t loc='arena';
\t \t $('#arena').css('display','');
\t \t $('#shop').css('display','none');
\t \t $('#house').css('display','none');
\t });
\t $('#gt-house').click(function(){
\t \t alert('house');
\t \t loc='house';
\t \t $('#house').css('display','');
\t \t $('#shop').css('display','none');
\t \t $('#arena').css('display','none');
\t });
\t $('#gt-shop').click(function(){
\t \t alert('shop');
\t \t loc='shop';
\t \t $('#house').css('display','none');
\t \t $('#shop').css('display','');
\t \t $('#arena').css('display','none');
\t });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<title>jquery problem</title>
<div id="house">
\t <h1>Your house</h1>
\t <p>This is your house</p>
\t <button id="gt-arena">Go to Arena</button>
\t <button id="gt-shop">Go to Shop</button>
</div>
<div id="arena">
\t <h1>Arena</h1>
\t <p>This is the Arena</p>
\t <button id="fight">Fight</button>
\t <button id="gt-house">Leave Arena</button>
\t <button id="gt-shop">Go to Shop</button>
</div>
<div id="shop">
\t <h1>Shop</h1>
\t <p>For all your shopping needs</p>
\t <button id="buy-knife">Buy knife</button>
\t <button id="gt-arena">Go to Arena</button>
\t <button id="gt-house">Go to House</button>
</div>
非常感谢你! – lemminkainen