javascript - 为什么添加后的行,删除和增加按钮点击都没有反应
本文介绍了javascript - 为什么添加后的行,删除和增加按钮点击都没有反应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
<title>demo about table</title>
</head>
<body>
<br/>
<table class="business_setboxc_01">
<thead>轻货阶梯价格</thead>
<tbody>
<tr>
<td>
<div class="form-group"> 超过
<input type="text" placeholder="1" size="5" class="form-control sel_add_01"> 公斤,
<input type="text" size="5" class="form-control sel_add_01"> 元/公斤 <span class="glyphicon glyphicon-plus">增加</span> <span class="glyphicon glyphicon-trash">删除</span>
</div>
</td>
</tr>
</tbody>
</table>
</body>
</html>
<script>
$(".glyphicon-trash").click(function(){
$(this).parents("tr").remove();
});
$(".glyphicon-plus").click(function() {
var flotr='<tr><td><div class="form-group"> 超过 <input type="text" placeholder="1" size="5" class="form-control input-smsel_add_01"> 公斤,<input type="text" size="5" class="form-control sel_add_01"> 元/公斤 <span class="glyphicon glyphicon-plus">增加</span> <span class="glyphicon glyphicon-trash">删除</span></div></td></tr>'
$(flotr).appendTo(".business_setboxc_01");
});
</script>
解决方案
$(document).on('click','.glyphicon-trash',function(){
$(this).parents("tr").remove();
});
$(document).on('click','.glyphicon-plus',function(){
//do something
});
这篇关于javascript - 为什么添加后的行,删除和增加按钮点击都没有反应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文