这是我正在制作如何制作互动/选择你自己的冒险故事的页面:http://victoriabrockmeier.com/querent/codetest.html
当用户点击单词"楼梯时,"我想添加课程#34;禁用"到那个元素,然后添加故事的下一部分。这是我认为相关的代码,从页面中拉出来:
<div id="ongoingStory"><p>This wasn’t where you meant to go.</p>
<p>You were walking, and thinking, and now that you’ve come back to the present, you’re looking at brick on two sides and a slatted, padlocked gate between them. You’ve come up an alley. Or down one.</p>
<p>Up a set of <a href="#" id="stairs">stairs</a> bolted precariously to one building’s brick side, there’s a door. Above it, a sign juts out: <span class="smcaps">Sparrow Aisling / Psychic</span>. Barely readable in the dusk, but there it is.</p></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="narrative.js"></script>
和叙述.js -
var climbStairs = "<p>You climb the stairs and go through the door.</p><p>Inside, there’s a red velvet sofa, diamond-tufted, and an ottoman to one side. Heavy green curtains and a spray of tiny, ornately framed <a href=\"#\">mirrors</a> occupy the back wall. Occult clutter fills the rest of the room — candles in cups, crystals, brass bells and bowls, figurines from a number of different religions, a little round tea set, and bundles of dried herbs and sticks.</p><p>The obligatory cat, gray, looks up at you, twitches its tail, and goes back to staring out the room’s one window.</p><ul><li><a href=\"#\">> Sit and wait.</a></li><li><a href=\"#\">> Nose around while you wait.</a></li></ul>"
$( document ).ready( function() {
$( "#stairs" ).click( function() {
$( this ).addClass( "disabled");
$( "#ongoingStory" ).append( climbStairs );
});
});
上一次我尝试编写比十年前的菜单栏更具互动性的脚本,所以请保持温和。我确定我对语法,或者需要处理的顺序完全错误,或者我没有逃避需要转义的东西,或者那些非常基本的东西。
答案 0 :(得分:0)
您发布的代码有效,但在您的页面上有以下行:
var sit = "<p>You settle on the velvet sofa, and the cat jumps down next to you. Assuming you’re not allergic to cats, you pet it, and it purrs. If you’re allergic, presumably you begin itching or sneezing, or both.</p><p>You’re now Patient.</p><p>After some time, a woman, bony and on the tall side, emerges from between the curtains.</p>
最后错过了结束"
。