[英]Read from a txt file - html/css website
I'm doing a personal page in which I have to include some kind of tooltip in css like this 我正在做一个个人页面,其中我必须像这样在css中包含某种工具提示
<a class="info" href="#">link<span>Your tooltip text here</span></a>
The css part: CSS部分:
a.info{
position:relative;
z-index:24;
color:#000;
text-decoration:none
}
a.info:hover{
z-index:25;
background-color: #FFF;
}
a.info span{
display: none
}
a.info:hover span{
display:block;
position:absolute;
top:2em;
left:2em;
width:15em;
border:1px solid #000;
background-color:#FFF;
color:#000;
text-align: justify;
font-weight:none;
padding:5px;
}
(I found the code on the net by the way) (我在网上找到了代码)
I just wondered if in was possible to have the "your tooltip text here" in a text file, either by using html, or javascript and get it to display the text which is inside the text file. 我只是想知道是否可以通过使用html或javascript在文本文件中包含“此处的工具提示文本”,并使其显示在文本文件中。
I must not use php for this. 我不能为此使用php。
Thanks. 谢谢。
JavaScript无法读取或写入文件...但是您可以使用Ajax从文本文件加载数据
You don't really need jQuery for this. 您真的不需要jQuery。 You can create a js file with your content that looks like this 您可以使用如下内容创建一个js文件:
var tips = new Array(
"My first tip",
"My second tip"
);
Then just use whatever version of this function you want to load the file. 然后,只需使用要加载文件的此功能的任何版本即可。 BTW why not use the title attribute to simulate the tooltips: <a class="info" href="#" title="Your tooltip text here">link</a>
Even if you want a fancy tooltip it seems better remove and then readd a title, rather than creating a whole separate element. 顺便说一句,为什么不使用title属性来模拟工具提示: <a class="info" href="#" title="Your tooltip text here">link</a>
即使您想要精美的工具提示,也最好将其删除并然后阅读标题,而不是创建整个单独的元素。
You can do this with ajax. 您可以使用ajax来执行此操作。 Use jQuery because there are many examples available there. 使用jQuery,因为那里有很多示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.