gpt4 book ai didi

jquery - 使用 jQuery 将类添加到单击的元素并将内容附加到 div

转载 作者:行者123 更新时间:2023-11-28 09:27:49 25 4
gpt4 key购买 nike

这是一个页面,我正在研究如何制作一个交互式/选择你自己的冒险故事:http://victoriabrockmeier.com/querent/codetest.html

当用户点击单词“stairs”时,我想向该元素添加“disabled”类,然后添加故事的下一段。这是我认为相关的代码,已从页面中提取出来:

<div id="ongoingStory"><p>This wasn&rsquo;t where you meant to go.</p>
<p>You were walking, and thinking, and now that you&rsquo;ve come back to the present, you&rsquo;re looking at brick on two sides and a slatted, padlocked gate between them. You&rsquo;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&rsquo;s brick side, there&rsquo;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>

来自 narrative.js --

var climbStairs = "<p>You climb the stairs and go through the door.</p><p>Inside, there&rsquo;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 &mdash; 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&rsquo;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 );
});

});

我上次尝试编写比菜单栏更具交互性的脚本是十多年前的事了,所以请保持温和。我确信我完全错误的语法,或者事物需要的顺序,或者我没有转义需要转义的东西,或者类似的非常基本的东西。

最佳答案

您发布的代码是有效的,但是在您的页面上有以下行:

var sit = "<p>You settle on the velvet sofa, and the cat jumps down next to you. Assuming you&rsquo;re not allergic to cats, you pet it, and it purrs.  If you&rsquo;re allergic, presumably you begin itching or sneezing, or both.</p><p>You&rsquo;re now Patient.</p><p>After some time, a woman, bony and on the tall side, emerges from between the curtains.</p>

末尾缺少结束符 "

关于jquery - 使用 jQuery 将类添加到单击的元素并将内容附加到 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25827335/

25 4 0
文章推荐: html - 如何使用元视口(viewport) "width=device-width"获得 100% 的 div 以完全覆盖页面的宽度
文章推荐: jquery - 如何独立检测悬停在 2 个部分重叠的
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com