克隆、追加和修改(青蛙)
在下面的 jQuery 示例中,在显示 HTML 克隆片段之前,如何更改文本“将“Remove Frog”更改为“Remove Frog #99”,并添加一个名为“frog99”的 id,其中 99 是序列号?
<div id='imageBox'>
</div>
<div class="hidden" id='template'>
<span class='alignRight'><a href='#' class='deleteFrog'>Remove Frog</a></span>
<span class='alignRight'><a href='#' class='addFrog'>Add Frog</a></span>
<img src="img/frog.jpg">
</div>
脚本:
var frogCount = 0;
$(document).ready(function() {
// listener: add "live" listener to link
$("#addFrog").live('click', function() {
// Clone hidden template
myClone = $("#template").clone();
// Before showing cloned object, I would like to change text "Remove Frog" to "Remove Frog #99".
// I think it should look something like this,
myClone.("a").text("Remove Frog #" + ++frogCount);
// Also add an id called "frog99", where 99 is a sequential number.
myClone.removeClass("hidden");
$('#imageBox').append(myClone);
});
});
In the jQuery example below, before showing a cloned segment of HTML, how do I change the text "Remove Frog" to "Remove Frog #99" and also add an id called "frog99", where 99 is a sequencing number?
<div id='imageBox'>
</div>
<div class="hidden" id='template'>
<span class='alignRight'><a href='#' class='deleteFrog'>Remove Frog</a></span>
<span class='alignRight'><a href='#' class='addFrog'>Add Frog</a></span>
<img src="img/frog.jpg">
</div>
Script:
var frogCount = 0;
$(document).ready(function() {
// listener: add "live" listener to link
$("#addFrog").live('click', function() {
// Clone hidden template
myClone = $("#template").clone();
// Before showing cloned object, I would like to change text "Remove Frog" to "Remove Frog #99".
// I think it should look something like this,
myClone.("a").text("Remove Frog #" + ++frogCount);
// Also add an id called "frog99", where 99 is a sequential number.
myClone.removeClass("hidden");
$('#imageBox').append(myClone);
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将行更改
为
Change the line
to