一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

jquery中append $(this) 使用问题解决方案

时间:2015-09-13 编辑:简简单单 来源:一聚教程网


js 代码

javascript">

$(document).ready(function(){

    

//标签操作

    $("[nctype='cms_tag']").live("click",function(){

        var current_css = $(this).attr("class");

        if(current_css == "btn-cms-tag") {

            $(this).attr("class","btn-cms-tag-selected");

        $("#tags_selected_place").append($(this));

        } else {

            $(this).attr("class","btn-cms-tag");

        $("#tags_place").append($(this));

        }

 

    });

 

});

 

html



 



 



爱人

爱马仕

爱琴海

爱运动

爱唯欧

爱丽丝梦游仙境


直接使用 append $(this) 这样的方法,jquery会吧$(this)元素直接从$("#tags_place")中删除,再添加到$("#tags_selected_place")元素中。

$("#tags_selected_place").append($(this));

 

如果想要保留$(this)原来的位置需要使用$(this).clone()方法

$("#tags_selected_place").append($(this).clone());

热门栏目