定位父div

时间:2015-12-08 09:01:13

标签: php arrays

我有以下php:

<?php echo '<div class="button_1" data-post_id="' .$id. '">' ;?>
     <div class="button_2">
        Button
     </div>
</div>

然后我的js:

jQuery(document).on( 'click', '.button_2', function(e) {    
    var post_id = jQuery(this).data("post_id");//??     
}

如何针对data-post_id div的{​​{1}}定位class="button_1"

由于

1 个答案:

答案 0 :(得分:1)

尝试使用<html> <head> <!--Import materialize.css--> <link type="text/css" rel="stylesheet" href="css/materialize.min.css" media="screen,projection"/> </head> <body> <!--Import jQuery before materialize.js--> <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script> <script type="text/javascript" src="js/materialize.min.js"></script> </body> </html> -

parents

或者

jQuery(this).parents('.button_1').data("post_id");
相关问题