dsvyc66464
2016-08-31 14:00
浏览 55

如何在同一个jQuery函数中获取不同跨度的值?

I have this code:

PHP:

<?php if ($row['Status'] == 'In Process'):?>                                    
    <span class="badge" style="background-color:#67A6DF">In Process</span>                                  
<?php endif; ?>
<?php if ($row['Status'] == 'Test'): ?>
    <span class="badge" style="background-color:#FCB529">In Test</span>
<?php endif;?>
<?php if ($row['Status'] == 'Approved'):?>
    <span class="badge" style="background-color:#43A995">Approved</span>                                                            
<?php endif;?>

jQuery:

$(document).ready(function() {
    $('.approved').on('click', function(){
        var process = $('.badge').html();       
        alert(process);     
    });//Onclick
});

Button:

<a href="javascript:void(0);" class="flex-icon approved" data-toggle="tooltip" data-placement="top" title="approve" data="5"><i class="fa fa-check-square-o fa-2x" aria-hidden="true"></i></a>

And I'm trying to get the text of the <span> tags, but every time I try to get it, it alerts the same text.

How do I get the value of different <span> tags in the same jQuery function?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dotxo86440 2016-08-31 16:21
    已采纳

    Try to change the jquery as below

    $(document).ready(function() {
        $('.approved').on('click', function(){
            $('span.badge').each(function() {
                alert( $(this).html());
            });       
    
        });//Onclick
    });
    
    点赞 打赏 评论

相关推荐 更多相似问题