jquery 动态生成的input添加change事件
借助js的on方法,可以给动态生成的input标签,添加change事件
1 //我的费率 2 $(document).on("input propertychange", "#mytbody .my_rate", function (e) { 3 var my_rate = $(this).val(); 4 var obj = $(this).parent().parent(); 5 var child_rate = $(obj.find('.child_rate')[0]).val(); 6 $(obj.find('.left_rate')[0]).val(parseFloat(my_rate)-parseFloat(child_rate)); 7 });
这是动态生成的html结构
1 <table > 2 <thead> 3 <tr> 4 <th width="3%"><div class="th-inner">ID</div><div class="fht-cell"></div></th> 5 <th width="10%"><div class="th-inner ">产品名称</div><div class="fht-cell"></div></th> 6 <th width="5%"><div class="th-inner ">产品分类</div><div class="fht-cell"></div></th> 7 <th width="5%"><div class="th-inner ">保费</div><div class="fht-cell"></div></th> 8 <th width="3%"><div class="th-inner ">总服务费率</div><div class="fht-cell"></div></th> 9 <th width="3%"><div class="th-inner ">下级分销服务费率</div><div class="fht-cell"></div></th> 10 <th width="3%"><div class="th-inner ">剩余自留费率</div><div class="fht-cell"></div></th> 11 <th width="3%"><div class="th-inner ">操作</div><div class="fht-cell"></div></th> 12 </tr> 13 </thead> 14 <tbody > 15 <tr > 16 <td >22</td> 17 <td >京彩一生百万医疗</td> 18 <td >意外险</td> 19 <td >0.00</td> 20 <td ><input class="form-control my_rate" type="number" ></td> 21 <td ><input class="form-control child_rate" type="number" ></td> 22 <td ><input class="form-control left_rate" type="number" ></td> 23 <td class="mydel" data->删除</td> 24 </tr> 25 <tr > 26 <td >27</td> 27 <td >平安一生</td> 28 <td >健康险</td> 29 <td >100000.00</td> 30 <td ><input class="form-control my_rate" type="number" ></td> 31 <td ><input class="form-control child_rate" type="number" ></td> 32 <td ><input class="form-control left_rate" type="number" ></td> 33 <td class="mydel" data->删除</td> 34 </tr> 35 </tbody> 36 </table>
使用bind方法不行,具体,on和bind和区别自行百度吧,我也不明白