【技术】动态创建div

点击前  点击后

 

html部分:

<body>

</body>

 

css部分:

.test1{
color: red;
cursor: pointer;
}
.test2{
color: blue;
}

 

js部分:

$(function() {
  $("<div>", {
    "class": "test1",
    text: "Click me!",
    click: function(){
      $(this).toggleClass("test2");
    }
  }).appendTo("body");
});

posted @ 2015-08-11 11:52  ybingbing_1213  Views(171)  Comments(0)    收藏  举报