[英]jQuery String selector add string from file
I have a line that creates a simple box like so:我有一行创建一个简单的框,如下所示:
var box = $('<button>').addClass('box');
With using the css:使用css:
.box {
border-radius: 0.7vw;
width: 40vw;
height: 50vw;
margin: 30px;
display: inline-block;
background-color: #d87c2d;
}
All fine, I get those boxes, I can even click on them.一切都好,我拿到了那些盒子,我什至可以点击它们。
But what I really need is generating some usable elements.但我真正需要的是生成一些可用的元素。
For that, I usually like to keep components separate (hope I use the correct terminology), so I made a text file with the following content:为此,我通常喜欢将组件分开(希望我使用正确的术语),所以我制作了一个包含以下内容的文本文件:
<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>
My goal is to put this inside the $(-here-)
instead of the simple <button>
I have there.我的目标是将它放在
$(-here-)
而不是我在那里的简单<button>
。
To get that I tried为了得到我试过
var box = $('/html/tileInside').addClass('box');
but didn't work, I believe JS thinks I want just the string
/html/tileInside there which obviously doesn't mean anything.但没有用,我相信 JS 认为我只想要
string
/html/tileInside ,这显然没有任何意义。
So is there a way to add a string
from a txt file inside the jQuery string selector?那么,有没有一种方法来添加一个
string
从jQuery串选择里面一个txt文件?
Use ajax here.在这里使用ajax。
$('<div></div>').load('/html/tileInside');
http://api.jquery.com/load/ http://api.jquery.com/load/
http://api.jquery.com/jQuery.ajax/ http://api.jquery.com/jQuery.ajax/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.