1

我有一个标准循环:

    <article class="somepost">  
       <?php       $a = get_the_title();   echo $a; ?>  
    </article> 

当我点击某篇文章(class="somepost")时,我如何获得某篇文章标题的价值

     $('.somempost').click(function(){ ??? });

谢谢。

4

1 回答 1

1

First, I would set the title to the articles data attribute:

<?php $a = get_the_title(); ?>
<article class="somepost" data-title="<?php echo $a; ?>">
    <?php echo $a; ?>
</article>

Then in your jQuery, set the title to a variable like so:

$('.somepost').click(function(){
    var the_title = $(this).data('title');
});
于 2013-02-14T03:59:29.453 回答