gpt4 book ai didi

javascript - jQuery 字符串选择器从文件中添加字符串

转载 作者:行者123 更新时间:2023-11-27 23:10:12 25 4
gpt4 key购买 nike

我有一行创建一个像这样的简单框:

var box = $('<button>').addClass('box');

使用CSS:

.box {
border-radius: 0.7vw;
width: 40vw;
height: 50vw;
margin: 30px;
display: inline-block;
background-color: #d87c2d;
}

很好,我得到了那些框,我什至可以点击它们。

但我真正需要的是生成一些可用的元素。

为此,我通常喜欢将组件分开(希望我使用正确的术语),所以我制作了一个包含以下内容的文本文件:

<div>
<div class="tile" id="eventName"> Event name</div><br/>
<div class="tile" id="eventDate">2017.01.01. </div>
<div class="tile" id="eventTime">12.00</div><br/>
<div class="tile" id="description">Some boring example description about the meaningless </div>
</div>

我的目标是将其放入 $(-here-) 中而不是简单的 <button>我那里有。

为了得到它,我试过了

var box = $('/html/tileInside').addClass('box');

但没用,我相信 JS 认为我只想要 string /html/tileInside 那里显然没有任何意义。

那么有没有办法添加一个string来自 jQuery 字符串选择器中的 txt 文件?

最佳答案

这里使用ajax。

$('<div></div>').load('/html/tileInside');

http://api.jquery.com/load/

http://api.jquery.com/jQuery.ajax/

关于javascript - jQuery 字符串选择器从文件中添加字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46525107/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com