0

jQuery と prettyPhoto (wordpress 用プラグイン) の使用に問題があります。私の問題は、既に機能しているタグの外側にある非表示の div から画像の説明を取得したいということです。これは私がこれまでに持っているものです:

<div class="portfolie_short_content_containe">                  
    <a class="lightbox" style="text-decoration: none;" rel="lightbox" href="<?php echo $image[0]; ?>" title="<?php echo $image_desc; ?>">
        <span class="hover">
            <div class="portfolio_thump_hover_text">
                <span class="lable"><?php echo $short_descr;?></span><br>
                <span class="lable"><?php echo $link;?></span><br>
                <span class="lable"><FONT style="color : #f47b42;">Se CV</FONT></span>
            </div>
        </span>
        <img src="<?php echo $image[0]; ?>" width="<?php echo $image[1]; ?>" alt="<?php echo $image_alt; ?>"></img>
    </a>

    <!-- hidden div containing description -->
    <div id="lightbox" style="display: none"><p><?php echo $full_descr; ?></p><div>
</div>

jQuery.prettyphoto.js ファイルは次のようになります。

theRel = $(this).attr('rel');
galleryRegExp = /\[(?:.*)\]/;
isSet = (galleryRegExp.exec(theRel)) ? true : false;
var x = 500;
var elmtid = $(this).attr('class');

// Put the SRCs, TITLEs, ALTs into an array.
pp_images = (isSet) ? jQuery.map(matchedObjects, function(n, i) {
    if ($(n).attr('rel').indexOf(theRel) != -1) 
        return $(n).attr('href'); 
}) : $.makeArray($(this).attr('href'));

pp_titles = (isSet) ? jQuery.map(matchedObjects, function(n, i) { 
    if ($(n).attr('rel').indexOf(theRel) != -1) 
        return ($(n).find('img').attr('alt')) ? $(n).find('img').attr('alt') : "";
}) : $.makeArray($(this).find('img').attr('alt'));

//Get text from hidden dir!     
pp_descriptions = (isSet) ? jQuery.map(matchedObjects, function(n, i) {
    if ($(n).attr('rel').indexOf(theRel) != -1) 
        return ($(n).find('p').text()) ? $(n).find('p').text() : ""; 
}) : $.makeArray($(this).find('p').text());

私はjQueryの経験がありません。説明を理解するのを手伝ってくれる人はいますか? 私はこのようなことを試しました!

pp_descriptions = (isSet) ? jQuery.map(matchedObjects, function(n, i) {
    if($(n).attr('class') != -1) 
        return ($('#'+elmtid).html()) ? $('#'+elmtid).html()  : \"\"; 
}) : $.makeArray($('#'+elmtid).html());

しかし、うまくいきませんでした。

4

1 に答える 1

0

解決しました、たぶん簡単ですが、初めてjQueryを操作しました!

<script type="text/javascript">
var $j = jQuery.noConflict();
$j(document).ready(function(){

//reference the class instead of a tag
$j("div[class^='portfolie_short_content_containe']").prettyPhoto({theme: '<?php echo $portfolio_options["prtfl_prettyPhoto_style"]; ?>'});
});
</script>

jsファイルでこれを変更しました。

theRel = $(this).find('a').attr('rel');
//theRel = $(this).attr('rel');
galleryRegExp = /\[(?:.*)\]/;
isSet = (galleryRegExp.exec(theRel)) ? true : false;
var x=500;

pp_images = $.makeArray($(this).find('a').attr('href'));
pp_titles = $.makeArray($(this).find('img').attr('alt'));
pp_descriptions =  $.makeArray($(this).find('p').html());

完璧ではありませんが、同じ問題を抱えている他の人に役立つことを願っています.

于 2012-09-06T08:17:08.030 に答える