0

jQuery Mobile Galleryという優れたフォト ギャラリーを使用していますが、問題があります。

次のようにテキストを alt プロパティまたは title プロパティに手動で入力する場合:

alt="Picture 1"正常に動作しますが、テキストが次のようにデータベースから取得された場合:

alt= row['description']「Picture 1」ではなく、テキストPictureを取るだけ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年10月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

バックエンド コードを見ずに推測する必要があります。altタグに必要なテキストを二重引用符で囲んでいないようです。

あなたはこれを持っています:

alt=Picture 1

あなたはこれを求めている:

alt="Picture 1"
于 2012-10-09T20:03:07.027 に答える