使用第二个toggle删除在第一个toggle中实现的span
Remove a span implemented in first toggle using second toggle
我在删除一个span时遇到了问题,该span是在第一次单击toggle时创建的,在第二次单击toggle时删除的。
$(document).ready(function(){
$("td").toggle(
function(){
var current = $("input[name=prices]:checked").val();
$(this).html("<img src='images/1.gif'/>");
$(".summary").append("<br><span class = 'newticket' id = 'null'>");
$("#null").attr("id",$(this).attr("id"));
$(".summary").append("1 x ");
if(current == 'full'){
$(".summary").append("full price ticket.");
}
$(".summary").append(" Seat: ");
$(".summary").append($(this).attr("id"));
if(current == 'full'){
$(".summary").append(" Price: £10</span>");
}
},
function(){
$(this).html("<img src='images/a.gif'/>");
$("span#" + $(this).attr("id")).remove();
});
});
如果我点击表的值,span就会被添加,但是如果我再次点击表的值,span就不会被删除。
不应该添加未关闭的标记创建一个字符串,然后追加它。完整的解决方案。
$(document).ready(function(){
$("td").toggle(
function(){
var current = $("input[name=prices]:checked").val();
$(this).html("<img src='images/1.gif'/>");
var html = "<br><span class = 'newticket' id = 'null'>";
htnl += "1 x ";
if(current == 'full'){
html +="full price ticket.";
}
html +=" Seat: " + $(this).attr("id");
$(".summary").append($(this).attr("id"));
if(current == 'full'){
html +=" Price: £10"
}
html += "</span>";
$(".summary") .append(html);
},
function(){
$(this).html("<img src='images/a.gif'/>");
$(".summary span.newticket").remove();
});
});
相关文章:
- 如何使用动画实现纸张推车
- 客户端服务器REST API captcha实现
- jQuery/Javascript.toggleClass/.classList.toggle的特殊行为
- 如何实现此布局
- Meteor忘记了密码的实现
- 使用Native Sockets在Android中实现WebSockets
- 在样板文件中实现Ajax
- instanceof是如何在JavaScript中实现的
- 如何正确实现Jquery多选小部件
- 实现一个建立在google.com之上的自定义搜索引擎
- 多个组件是如何实现的
- window.location使用jquery mobile实现chrome跳转
- 如何在OpenERP中实现网络摄像头
- Node.js使用Series函数(模式?)实现流控制时出现意外结果
- javascript加密实现,包括可信否认
- 实现比较方法的最佳实践是什么;s的比较类型是在运行时选择的
- 如何让程序员在javascript中实现正确的回调
- 如何使用自定义辅助对象(handler)实现嵌套的每个循环
- AngularJS智能表全局配置实现
- 使用第二个toggle删除在第一个toggle中实现的span