2010-11-09 149 views
0

我試圖根據類名和rel屬性替換div。jQuery替換基於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> 

你會怎麼做?

回答

2

試試這個:

$(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); 
    }); 
}); 
+1

很好,謝謝!我會立即嘗試 – Phil 2010-11-09 17:15:35

+0

@菲爾,不客氣! :-) – 2010-11-09 17:16:22