代码之家  ›  专栏  ›  技术社区  ›  Phil

基于rel属性的jQuery替换div

  •  0
  • Phil  · 技术社区  · 15 年前

    我试图基于类名和rel属性替换div。

       <script type="text/javascript">
    
            $(function () {
    
                $('.special_button').click(function () {
    
                    var num = $(this).attr('rel');
    
                    $(button with class .value_button and rel=num).replaceWith("<div class='value_button' >" + $(this).val() + "</div>");
                    $('div.content_slide').slideUp(600);
                });
            });
    
        </script>
    

    1 回复  |  直到 15 年前
        1
  •  2
  •   Jacob Relkin    15 年前

    试试这个:

    $(function () {
    
       $('.special_button').click(function () {
    
           var num = $(this).attr('rel');
    
           $('.value_button[rel="' + num + '"]').replaceWith("<div class='value_button' >" + $(this).val() + "</div>");
           $('div.content_slide').slideUp(600);
       });
    });