jquery 动态生成的input添加change事件
借助js的on方法,可以给动态生成的input标签,添加change事件
//我的费率 $(document).on("input propertychange", "#mytbody .my_rate", function (e) { var my_rate = $(this).val(); var obj = $(this).parent().parent(); var child_rate = $(obj.find(‘.child_rate‘)[0]).val(); $(obj.find(‘.left_rate‘)[0]).val(parseFloat(my_rate)-parseFloat(child_rate)); });
这是动态生成的html结构
<table id="table" class="table table-striped table-bordered table-hover table-nowrap" width="100%"> <thead> <tr> <th style="text-align: center; vertical-align: middle;" width="3%"><div class="th-inner">ID</div><div class="fht-cell"></div></th> <th style="text-align: center; vertical-align: middle;" width="10%"><div class="th-inner ">产品名称</div><div class="fht-cell"></div></th> <th style="text-align: center; vertical-align: middle;" width="5%"><div class="th-inner ">产品分类</div><div class="fht-cell"></div></th> <th style="text-align: center; vertical-align: middle;" width="5%"><div class="th-inner ">保费</div><div class="fht-cell"></div></th> <th style="text-align: center; vertical-align: middle;" width="3%"><div class="th-inner ">总服务费率</div><div class="fht-cell"></div></th> <th style="text-align: center; vertical-align: middle;" width="3%"><div class="th-inner ">下级分销服务费率</div><div class="fht-cell"></div></th> <th style="text-align: center; vertical-align: middle;" width="3%"><div class="th-inner ">剩余自留费率</div><div class="fht-cell"></div></th> <th style="text-align: center; vertical-align: middle;" width="3%"><div class="th-inner ">操作</div><div class="fht-cell"></div></th> </tr> </thead> <tbody id="mytbody"> <tr id="0-id"> <td style="text-align: center; vertical-align: middle;" id="22-myid" data-value="22">22</td> <td style="text-align: center; vertical-align: middle;" id="22-myname" data-value="京彩一生百万医疗">京彩一生百万医疗</td> <td style="text-align: center; vertical-align: middle;" id="22-jq_category_name" data-value="意外险">意外险</td> <td style="text-align: center; vertical-align: middle;" id="22-premium" data-value="0.00">0.00</td> <td style="text-align: center; vertical-align: middle;"><input class="form-control my_rate" type="number" id="22-my_rate" value="15"></td> <td style="text-align: center; vertical-align: middle;"><input class="form-control child_rate" type="number" id="22-child_rate" value="8"></td> <td style="text-align: center; vertical-align: middle;"><input class="form-control left_rate" type="number" id="22-left_rate" value="5"></td> <td style="text-align: center; vertical-align: middle;" class="mydel" data-id="0">删除</td> </tr> <tr id="1-id"> <td style="text-align: center; vertical-align: middle;" id="27-myid" data-value="27">27</td> <td style="text-align: center; vertical-align: middle;" id="27-myname" data-value="平安一生">平安一生</td> <td style="text-align: center; vertical-align: middle;" id="27-jq_category_name" data-value="健康险">健康险</td> <td style="text-align: center; vertical-align: middle;" id="27-premium" data-value="100000.00">100000.00</td> <td style="text-align: center; vertical-align: middle;"><input class="form-control my_rate" type="number" id="27-my_rate" value="20"></td> <td style="text-align: center; vertical-align: middle;"><input class="form-control child_rate" type="number" id="27-child_rate" value="5"></td> <td style="text-align: center; vertical-align: middle;"><input class="form-control left_rate" type="number" id="27-left_rate" value="5"></td> <td style="text-align: center; vertical-align: middle;" class="mydel" data-id="1">删除</td> </tr> </tbody> </table>
使用bind方法不行,具体,on和bind和区别自行百度吧,我也不明白
相关推荐
donghongbz 2020-03-04
开心就好 2020-06-10
huha 2020-10-16
TLROJE 2020-10-26
echoes 2020-08-20
nercon 2020-08-01
zhanghaibing00 2020-06-28
Aveiox 2020-06-25
henryzhihua 2020-06-21
zhoutaifeng 2020-06-17
liangzhouqu 2020-06-16
TONIYH 2020-06-11
x青年欢乐多 2020-06-06
KyrieHe 2020-06-03
bertzhang 2020-06-02
haokele 2020-05-29
niehanmin 2020-05-28