我有一个<li>
里面有 JQuery 代码的项目。我想克隆它<li>
并$.getJSON url
在 cloned 内部进行更改<li>
。是否可以?
这里的代码:
<ul class="exercise2">2:2 Exercise - 1
<li class="exset327" id="exset327"><var class="exset">327</var>:Сет - <var class="setnum">1</var>
<a class="DelSet" href="#">[-]</a>
<script>
$(".exset327 a").click(function () {
$.get("/workouts/del_set/327/"); // Here I want to change '327' in cloned item to some variable then clone
$(this).parent().remove();
$(".exercise2 li").each(function(){
$(".setnum",this).html($(this).index() + 1);
});
return false;
});
</script>
</li>
<a class="AddSet" href="#">Add set</a> // link which make a clone of above <li>
<script>
$(".exercise2 a.AddSet").click(function () {
$.getJSON("/workouts/add_set/2/", function (json) {
//alert(json.newsetnum);
var newsetid = json.newsetid; // returnet from server
var newsetnum = json.newsetnum; // returned from server
// clone
var clonedLi = $(".exercise2 li:last").clone(true); // 'true' to clone with event handler
// change attributes
$(clonedLi).attr("id", "exset" + newsetid);
$(clonedLi).attr("class", "exset" + newsetid);
// change content
$(clonedLi).find(".exset").html(newsetid);
$(clonedLi).find(".setnum").html(newsetnum);
// add
$(clonedLi).insertAfter(".exercise2 li:last");
});
});
</script>
</ul>
如果我在克隆URL
时单击(删除)链接时不会更改,则删除以前的链接。[-]
<li>