【问题标题】:jquery mobile gallery show just first word of the alt descriptionjquery mobile gallery 仅显示 alt 描述的第一个单词
【发布时间】:2012-09-30 05:11:23
【问题描述】:

我正在使用一个名为 jQuery Mobile Gallery 的很棒的照片库,但有一个问题。

如果你像这样手动将文本放在 alt 属性或 title 属性中:

alt="Picture 1" 工作正常,但如果文本是这样从数据库中获取的:

alt= row['description'] 它只取文本图片,而不是“图片 1”(row['description'] 具有正确的值,经过测试)。

所以,对于图像的更复杂的描述,我总是得到第一个词;

这是代码:

$(function(){   

    function gonext() {
        var current = $('a.selectedimg');
        if (current.hasClass('last')) {
            if (current.hasClass('first')) {
                $('#nextbtn').button("disable");
                $('#prevbtn').button("disable");
            }else {
                var next = $('a.first')
            }
        } else {
            var next = current.next();
        }

        var src = next.find('img').attr("src");
        var alt = next.find('img').attr("alt");
        var title = next.find('img').attr("title");
        alert("gonext.title: "+ title);
        next.addClass('selectedimg');
        current.removeClass('selectedimg');
        $('#dialogcontent').empty().append('<a href="#gallerypage"><img src="' + src + '" style="width:100%; height:100%;"/></a>' );
        $('#dialoghead').empty().append('<center><h6>' + title + '</h6></center>' );

    } 

    function goprev() {
        var current = $('a.selectedimg');
        if (current.hasClass('first')) {
            if (current.hasClass('last')) {
                $('#nextbtn').button("disable");
                $('#prevbtn').button("disable");
            }else {
                var prev = $('a.last')
            }

        } else {
            var prev = current.prev();
        }
        var src = prev.find('img').attr("src");
        var alt = prev.find('img').attr("alt");
        var title = prev.find('img').attr("title");
        prev.addClass('selectedimg');
        current.removeClass('selectedimg');
        $('#dialogcontent').empty().append('<a href="#gallerypage"><img src="' + src + '" style="width:100%; height:100%;"/></a>' );
        $('#dialoghead').empty().append('<center><h6>' + title + '</h6></center>' );
    }

    $('.gallerycontent img').bind('tap',function(event, ui){
        var src = $(this).attr("src");
        var alt = $(this).attr("alt");
        var title = $(this).attr("title");


        alert("gallerycontent.title: "+title );

        $('#dialogcontent').empty().append('<a href="#gallerypage"><img src="' + src + '" style="width:100%; height:100%;"/></a>' );
        $('#dialoghead').empty().append('<center><h6>' + title + '</h6></center>' );
        $(this).parent().addClass('selectedimg');
    });

    $('#nextbtn').bind('tap',function(event, ui){
        gonext();
    });

    $('#imgshow').bind('swipeleft',function(event, ui){
        gonext();
    });

    $('#prevbtn').bind('tap',function(event, ui){
        goprev();
    });

    $('#imgshow').bind('swiperight',function(event, ui){
        goprev();
    });
});

知道为什么会这样吗?或者如何解决?

谢谢。

这是 php 文件 (11/oct/2012) 中的代码:

                    $index = 1;
                    while ($row = mysql_fetch_array($result)) {
                        if ($index == 1) {
                            if ($n_reg == 1) {
                                echo "<a href=\"#imgshow\" data-transition=\"pop\" data-rel=\"dialog\" class=\"first last\" ><img src=" . $row['foto'] . " alt=" . $row['descripcion'] . " title=" . $row['descripcion'] . "/></a>"; 
                            } else {
                                echo "<a href=\"#imgshow\" data-transition=\"pop\" data-rel=\"dialog\" class=\"first\"><img src=" . $row['foto']  . " alt=" . $row['descripcion'] . " title=" . $row['descripcion'] . "/></a>";
                            }
                        } else if ($index == $n_reg) {
                            echo "<a href=\"#imgshow\" data-transition=\"pop\" data-rel=\"dialog\" class=\"last\"><img src=" . $row['foto'] ."  alt=" . $row['descripcion'] . " title=" . $row['descripcion'] . "/></a>";
                        } else {
                            echo "<a href=\"#imgshow\" data-transition=\"pop\" data-rel=\"dialog\" ><img src=" . $row['foto'] . " alt=" . $row['descripcion'] . " title=" . $row['descripcion'] . " /></a>";
                        }
                        $index++;
                    }

【问题讨论】:

    标签: jquery image gallery bind attr


    【解决方案1】:

    没有看到后端代码,我不得不猜测。您似乎在 alt 标记所需的文本周围缺少双引号。

    你有这个:

    alt=Picture 1
    

    你想要这个:

    alt="Picture 1"
    

    【讨论】:

    • 如果您发布生成此代码的后端代码,我们可以帮助您对其进行排序。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-06
    • 2014-10-21
    • 1970-01-01
    • 2012-05-09
    • 2012-11-27
    • 1970-01-01
    相关资源
    最近更新 更多