简体   繁体   English

javascript错误,PHP变量在codeigniter中传递

[英]javascript error with php variable passing in codeigniter

function something(frm,i){
//var ch=frm.outof1.value;
for(var j=1;j<=i;j++)
{
    //var b="outof" + j;
    alert(frm.outof+j.value);

}
//alert("outof" + i);
return false;
}

 $js='onClick="something(this.form,\''. $ii .'\')"';
  echo form_button('mybutton', 'Click Me', $js);

and getting output NAN where in html this is // echo form_input('outof'.$i,''); 并获取输出NAN,在html中// // echo form_input('outof'。$ i,''); // the form input. //表单输入

First, you will want to make sure the passed $ii is made into the correct type (not a string) by using parseInt . 首先,您将要使用parseInt确保将传递的$ii为正确的类型(而不是字符串)。 Then you construct the form input name by concatenating 'outof' and the number before evaluating .value . 然后,您可以通过在评估.value之前将'outof'和数字连接起来来构造表单输入名称。

function something(frm, i)
{
    for(var j = 1; j <= parseInt(i); ++j) {
        alert(frm['outof' + j].value);
    }
}
alert(parseInt(frm.outof) + parseInt(j.value))

最有可能的是,您试图求和字符串而不是整数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM