I'm doing a personal page in which I have to include some kind of tooltip in css like this
<a class="info" href="#">link<span>Your tooltip text here</span></a>
The css part:
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.
I must not use php for this.
Thanks.
JavaScript can't read or write files ... But you can load the data from a text file with Ajax
You don't really need jQuery for this. You can create a js file with your content that looks like this
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.
You can do this with ajax. Use jQuery because there are many examples available there.
精彩评论