0

我正在使用一个名为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 文件中的代码(2012 年 11 月 11 日):

                    $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++;
                    }
4

1 回答 1

0

Without seeing the backend code, I have to guess. It looks like you are missing double quotes around the text that you want for the alt tag.

you have this:

alt=Picture 1

you want this:

alt="Picture 1"
于 2012-10-09T20:03:07.027 回答