简体   繁体   English

标题属性中的img标签

[英]img tag within title attribute

I have read this question: How to add image tag inside title attribute of an anchor tag? 我已经读过这个问题: 如何在锚标记的title属性内添加图像标记? and got only one answer: "imposible". 并且只有一个答案:“不可能”。 However, I saw they can do it in this page: http://truyen.vnsharing.net/Nhom/GoldenSun---yurivn-net 但是,我看到他们可以在此页面中执行此操作: http : //truyen.vnsharing.net/Nhom/GoldenSun---yurivn-net

I viewed the page's source and got: 我查看了页面的来源并得到:

<a href="/Truyen/Citrus-Saburo-Uta?id=7048" title='
            <img width="120" height="165" src="http://truyen4.vnsharing.net/Uploads4/Etc/5-1-2013/12456468861citrus_ch01_02-03.jpg" style="float: left; padding-right: 10px" />
            <div style="float: left; width: 300px">
                <a class="bigChar" href="/Truyen/Citrus-Saburo-Uta">Citrus (Saburouta)</a>
                <p>
                    Nh&acirc;n vật ch&iacute;nh Yuzuko, ngay ng&agrave;y đầu ti&ecirc;n chuyển trường đ&atilde; đụng mặt v&agrave; kh&ocirc;ng mấy cảm t&igrave;nh với Mei - hội trưởng hội học sinh ở &nbsp;trường mới, trong ...
                </p>
            </div>'>
            Citrus (Saburouta)</a>

but the image was not displayed when I put those html code on my website. 但是当我将这些html代码放在我的网站上时,该图片未显示。 So how could they do that? 那么他们该怎么做呢? Are they using some js script, or something like that? 他们使用的是js脚本还是类似的脚本?

To quote the accepted answer to the question you linked to 引用您链接到的问题的可接受答案

You need to use custom tooltip look-a-like effect with IMG insdie DIV and on mouseHover event. 您需要对IMG insdie DIV和mouseHover事件使用自定义工具提示类似效果。

They use a custom tooltip look-a-like effect. 他们使用自定义工具提示类似效果。

As other have mentioned you cannot place HTML content inside of "title" attribute - it has to be something custom. 正如其他人提到的那样,您不能将HTML内容放在“ title”属性内-它必须是自定义的。

For pure CSS solution (that does not involve JavaScript and mouse-over events) you can place the DIV with tooltip content next to your link, set its style to "display: none" and give your anchors style like 对于纯CSS解决方案(不涉及JavaScript和鼠标悬停事件),您可以在链接旁边放置带有工具提示内容的DIV,将其样式设置为“ display:none”,然后将锚点样式设置为

a:hover + div {
   display: block !important
}

this will select DIV adjuncted to link and make it visible, but only when you hover over link. 这将选择附加的DIV进行链接并使其可见, 仅当您将鼠标悬停在链接上时。 You can make it more granular by targeting specific links instead of all of them as the code above. 您可以通过定位特定的链接(而不是上面的代码中的所有链接)来使其更精细。

Here is the demo: http://jsfiddle.net/4WZvL/ 这是演示: http : //jsfiddle.net/4WZvL/

The image tag in that title attribute is encoded. 该标题属性中的图像标签已编码。 Given this, you can place any string you want in the title tag of an anchor, it doesn't mean it's a good idea at all though. 有了这个,您可以将任何所需的字符串放在锚点的标题标签中,但这并不意味着它是个好主意。 You can use javascript to pull the proper image url from any data attribute you set and achieve the same effect so long as you know how to use that url in a logical way. 您可以使用javascript从您设置的任何数据属性中提取适当的图片网址,并获得相同的效果,只要您知道如何以合理的方式使用该网址即可。 At least that way you would be following some kind of standard and not just abusing the intention of html standards to pull off some fancy tricks. 至少以这种方式,您将遵循某种标准,而不仅仅是滥用html标准的意图以获取一些幻想。

Juhana answered your question. Juhana回答了您的问题。 But to extend the notion, you can easily use data attributes, id's, and classes to set hidden or otherwise referenced html elements for whatever you need. 但是要扩展这个概念,您可以轻松地使用数据属性,ID和类来设置隐藏的或以其他方式引用的html元素,以供您使用。 You can hide elements with css and then unhide them with javascript if the desired effect is to pop up that block with the images from the link you provided. 如果想要的效果是使用您提供的链接中的图像弹出该块,则可以使用CSS隐藏元素,然后使用javascript取消隐藏它们。

Someone may provide an example if you specify your exact needs and show what you have tried to solve it yourself. 如果您指定确切的需求并展示自己尝试解决的问题,则可以提供一个示例。

That HTML isn't valid, and although it might be possible it doesn't mean you should do it. HTML无效,尽管可能,但这并不意味着您应该这样做。 Some browsers probably won't display the image correctly. 某些浏览器可能无法正确显示图像。

Use one of the thousands of Javascript tooltip plugins instead. 请改用数千个Javascript工具提示插件之一。 Here's loads for jQuery: https://www.google.co.uk/search?q=jquery+tooltip+plugin 这是jQuery的负载: https : //www.google.co.uk/search? q = jquery+tooltip+ plugin

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM