簡體   English   中英

無法綁定點擊事件

[英]Can't bind click event

我對函數“ add_reg”進行了調用,但是當添加新行時,click事件不起作用,會發生什么? 謝謝

function add_reg(){
cant_empleados++; 
if($('#id_zona').val() == 2){
    var nuevo_reg = '<div style="clear:both"></div><div id="empleado_' + cant_empleados + '" class="cont_empleado" onmouseover="this.style.background=\'#F2F2F2\';" onmouseout="this.style.background=\'#FFFFFF\';"><div style="float:left; width:136px; padding-left:15px"><input name="existe_emp' + cant_empleados + '" id="existe_emp' + cant_empleados + '" type="hidden" value="n" /><input name="existe_reg' + cant_empleados + '" id="existe_reg' + cant_empleados + '" type="hidden" value="n" /><input name="cuil' + cant_empleados + '" type="text" id="cuil' + cant_empleados + '" value="" style="width:130px" alt="99-99999999-9" onblur="buscarNombre(this.value, ' + cant_empleados + ');" maxlength="13"   tabindex="' + tab++ + '"/></div><div style="float:left; width:256px"><input name="apellido_y_nombre' + cant_empleados + '" type="text" id="apellido_y_nombre' + cant_empleados + '" style="width:250px"  maxlength="20" tabindex="' + tab++ + '" value=""/></div><div style="float:left; width:106px"><input name="categoria' + cant_empleados + '" type="text" id="categoria' + cant_empleados + '" value="" style="width:100px"  maxlength="7" tabindex="' + tab++ + '"/></div><div style="float:left; width:96px"><input name="retribucion_mensual' + cant_empleados + '" type="text" id="retribucion_mensual' + cant_empleados + '" alt="decimal" style="width:90px" onblur="calcular_porcentaje(' + cant_empleados + ');"  tabindex="' + tab++ + '" value="" /></div><div style="float:left; width:auto"><input name="cotizacion_sindical' + cant_empleados + '" type="text" id="cotizacion_sindical' + cant_empleados + '" alt="decimal"  value="" style="width:80px; background-color:#F1F1F1" readonly="readonly" />&nbsp;</div><div style="float:left; width:auto">  <input type="checkbox" name="imputar_sss' + cant_empleados + '" id="imputar_sss' + cant_empleados + '" value="' + cant_empleados + '"  checked="checked" /> <input name="sistema_social_solidario' + cant_empleados + '" type="text" id="sistema_social_solidario' + cant_empleados + '" alt="decimal"  value="" style="width:55px; background-color:#F1F1F1" readonly="readonly" />&nbsp;</div><div style="float:left; width:auto">  <input type="checkbox" name="imputar_rpp' + cant_empleados + '" id="imputar_rpp' + cant_empleados + '" value="' + cant_empleados + '" checked="checked" /> <input name="prestaciones_previsionales' + cant_empleados + '" type="text" id="prestaciones_previsionales' + cant_empleados + '" alt="decimal"  value="" style="width:55px; background-color:#F1F1F1" readonly="readonly" />&nbsp;</div><div style="float:left; width:auto">  <a href="javascript:borrar_reg(' + cant_empleados + ')" title="Borrar registro" onclick="return confirm(\'¿Esta seguro de querer borrar este registro?\');"><img src="./images/ic_borrar.gif" alt="Borrar" /></a></div></div>';
}else{
    var nuevo_reg = '<div style="clear:both"></div><div id="empleado_' + cant_empleados + '" class="cont_empleado" onmouseover="this.style.background=\'#F2F2F2\';" onmouseout="this.style.background=\'#FFFFFF\';"><div style="float:left; width:136px; padding-left:15px"><input name="existe_emp' + cant_empleados + '" id="existe_emp' + cant_empleados + '" type="hidden" value="n" /><input name="existe_reg' + cant_empleados + '" id="existe_reg' + cant_empleados + '" type="hidden" value="n" /><input name="cuil' + cant_empleados + '" type="text" id="cuil' + cant_empleados + '" value="" style="width:130px" alt="99-99999999-9" onblur="buscarNombre(this.value, ' + cant_empleados + ');" maxlength="13"   tabindex="' + tab++ + '"/></div><div style="float:left; width:256px"><input name="apellido_y_nombre' + cant_empleados + '" type="text" id="apellido_y_nombre' + cant_empleados + '" style="width:250px"  maxlength="20" tabindex="' + tab++ + '" value=""/></div><div style="float:left; width:106px"><input name="categoria' + cant_empleados + '" type="text" id="categoria' + cant_empleados + '" value="" style="width:100px"  maxlength="7" tabindex="' + tab++ + '"/></div><div style="float:left; width:96px"><input name="retribucion_mensual' + cant_empleados + '" type="text" id="retribucion_mensual' + cant_empleados + '" alt="decimal" style="width:90px" onblur="calcular_porcentaje(' + cant_empleados + ');"  tabindex="' + tab++ + '" value="" /></div><div style="float:left; width:auto"><input name="cotizacion_sindical' + cant_empleados + '" type="text" id="cotizacion_sindical' + cant_empleados + '" alt="decimal"  value="" style="width:80px; background-color:#F1F1F1" readonly="readonly" />&nbsp;</div><div style="float:left; width:auto"> <input name="sistema_social_solidario' + cant_empleados + '" type="text" id="sistema_social_solidario' + cant_empleados + '" alt="decimal"  value="" style="width:80px; background-color:#F1F1F1" readonly="readonly" />&nbsp;</div><div style="float:left; width:auto"> <input name="prestaciones_previsionales' + cant_empleados + '" type="text" id="prestaciones_previsionales' + cant_empleados + '" alt="decimal"  value="" style="width:80px; background-color:#F1F1F1" readonly="readonly" />&nbsp;</div><div style="float:left; width:auto">  <a href="javascript:borrar_reg(' + cant_empleados + ')" title="Borrar registro" onclick="return confirm(\'¿Esta seguro de querer borrar este registro?\');"><img src="./images/ic_borrar.gif" alt="Borrar" /></a></div></div>';
}
$("#totales").before(nuevo_reg);
$("#empleado_" + cant_empleados).hide();
$("#empleado_" + cant_empleados).fadeIn();
$("#cant_empleados").val(cant_empleados);
$("#cuil" + cant_empleados).setMask();
$("#retribucion_mensual" + cant_empleados).setMask();

try{
    setActionImputar('#imputar_sss' + cant_empleados);
    setActionImputar('#imputar_rpp' + cant_empleados);
}catch(e){
    //  no hago nada
}}

function setActionImputar(selector){
$(selector).click(function(){
    calcular_porcentaje($(this).val());
});}

您應該使用實時綁定

function setActionImputar(selector){
$(selector).live('click', function(){
    calcular_porcentaje($(this).val());
}); 
}

使用實時綁定事件。

function setActionImputar(selector){
   $(selector).live('click', function(){
       calcular_porcentaje($(this).val());
   }); 
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM