在javascript中的Onclick事件

时间:2016-01-25 05:54:57

标签: javascript php jquery html

我的英语不好但我需要帮助!我正在向表中添加动态行,在行输入中使用类型复选框。我需要使用onclick事件复选框,但我不能这样做。

 $('#nuevo').click(function() {

//adding a row

     var idusu = "<?php echo $idusuariologeado; ?>" ;
 var fila='<tr><td>&nbsp;</td>'+

 '<td><input name="idiomas_nombre[]" type="text" placeholder="Idioma" 
  class="form-control input-md"  /><input  name="idiomas_usu[]" type="text" 
   value="'+ idusu + '" > </td>'+

  '<td><input  name="" type="checkbox" value="1" ><input type="hidden" 
   name="idiomas_suficiencia[]" value="" /></td>'+

   '<td><input id="cb2"  name="" type="checkbox" onclick="updatebox()" 
   value="1" /><input type="text" name="idiomas_escritura[]"  /></td>'+

   '<td><input id="cb3"  name="" type="checkbox" value="1"  >
   <input type="hidden" name="idiomas_lectura[]" value="1" /></td>'+

   '<td align="center"><input id="cb4" name="" type="checkbox" value="1" >     
   <input type="text" name="idiomas_hablado[]" value="1" /></td></tr>';


 //row to table
$('#tab_logic').append(fila);




  });

我打算在onclick

中使用的功能
function updatebox()
{
var textbox = document.getElementById("idiomas_escritura");
var values = [];

if(document.getElementById('cb2').checked) {
    values.push("1");
}

if(document.getElementById('cb3').checked) {
    values.push("1");
}

if(document.getElementById('cb4').checked) {
    values.push("1");
}


    textbox.value = values.join(" ");
}

请帮帮我。感谢的

1 个答案:

答案 0 :(得分:1)

没有id =&#34; nuevo&#34;的标记,只需将id属性添加到任何元素