【问题标题】:Open image via DIV data通过 DIV 数据打开图像
【发布时间】:2026-02-19 06:15:01
【问题描述】:

再次请求您的帮助,我有一个 ftp,我想在其中使用一些音乐翻唱 http://inlivefm.6te.net/capas/

我还有一个 javascript,它给了我封面链接的数据:他现在要提供的链接 http://inlivefm.6te.net/capas/I需要你的爱.jpg 最后播放的歌曲

我使用 JavaScript 来提供封面

<head>
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            //  Defino my variable global
            var myObj = {}; 
            $.ajax({
                type: "GET",
                url: "/AirPlayHistory.xml",
                dataType: "xml",
                success: function(xml) {
                    $(xml).find('Song').each(function() {
                        //  Definimos el atributo tittle
                        myObj.tittle = $(this).attr('title');

                        $(this).find('Artist').each(function() {
                            //  Definimos el atributo artist
                            myObj.artist = $(this).attr('name');
                        });

                        $(this).find('Info').each(function() {
                            //  Definimos el atributo time
                            myObj.time = $(this).attr('StartTime');
                        });

                        $(this).find('Info').each(function() {
                            //  Definimos el atributo cover
                            myObj.cover = $(this).attr('JazlerID');
                        });

                        //  Por ultimo lo mostramos :)
                        $('.cancion').html("<p>http://inlivefm.6te.net/capas/" + myObj.tittle + ".jpg</p>");
                    });
                }
            });         
        });
    </script>
</head>
<body>
    <div class="cancion"></div>
</body>
</html>

知道div给了我封面的链接,想打开提供数据的直通图

<img src="<div class="cancion"></div>
"/>

我想要的例子是这样的:

<img src="http://inlivefm.6te.net/capas/I NEED YOUR LOVE.jpg"/>

我正在尝试这样做,但由于图像无法打开,所以我无法做到,所以我来寻求您的帮助。

非常感谢!

【问题讨论】:

  • 你有一个 IMG 标签,里面有一个 DIV 标签。这是故意的吗? HTML 代码不是图像的有效来源,您应该为您的 IMG 提供一个 ID 并使用 Javascript 更改来源。
  • @goncalopinto 目标是 div 提供的链接是打开的图像,看起来不像他在做的那样
  • 你的意思是像
    inlivefm.6te.net/capas/I%20NEED%20YOUR%20LOVE.jpg"></…> 吗?
  • 不,这根本不起作用。你需要类似$('.cancion').html('&lt;img src="http://inlivefm.6te.net/capas/' + myObj.tittle + '.jpg"&gt;');
  • @ClaudioKing 是的,封面链接后面的 DIV 广告,我想要的是打开 DIV 链接以获取封面

标签: javascript jquery html css


【解决方案1】:

我相信你想要一张图片,点击它会带你到另一个资源;这样做:

<a href='resource.URL' ><img src='image.URL' other_attributes /></a>

点击image.URL会带你到resource.URL

【讨论】:

  • 我想要什么,即使她很快就打开而无需点击任何东西,但正如我所说,我将 div 放在 img 中无处可寻
  • 不,你需要 src="inlivefm.6te.net/capas/I NEED YOUR LOVE.jpg"
  • 是的,但是由于 xml 将处于活动状态,所以封面总是在变化,因此 DIV 的重要性,所以它不交换封面并且始终相同
  • 那么,您想要一个内部带有图像的 DIV 并使其表现为链接但不使用 IMG 和 A 标签?只有DIV?是这样吗?
  • @goncalopinto 他可以使用带有 background-image 在 CSS 中指定的 div,每个 div 都有一个单独的类!
猜你喜欢
相关资源
最近更新 更多
热门标签