简体   繁体   English

将值作为onchange()事件中定义的函数的参数传递

[英]Passing values as arguments of a function defined in onchange() event

I want to pass a value as an argument of a function. 我想传递一个值作为函数的参数。 The function is defined on onchange() of a text field. 该函数在文本字段的onchange()上定义。 I am using the following code..I use zend form to create the element. 我使用以下代码。我使用zend表单来创建元素。

$filedName = "cust_attr_".($i+1);
$fieldArr[$i]       =   $this->createElement('Text',$filedName)
-> setAttrib('class','k-textbox float_left input_width_295 k-invalid')
-> setAttrib('onchange','validateDataType('.$customerAttributes[$i]['data_type'].')')
-> setAttrib('maxlength','14')
-> setAttrib('tabindex',(++$tabStart));

And when i run the code i am getting the value as the argument of function..Like 当我运行代码时,我得到的值是函数的参数。就像

onchange="validateDataType(A)"

But i am getting an error Uncaught ReferenceError: A is not defined 但我得到一个错误未捕获的ReferenceError:A未定义

How to solve this??? 怎么解决这个???

"A" should be passed as a string. “A”应该作为字符串传递。 Without the quotes it looks for A as an object. 如果没有引号,它会将A作为对象。

-> setAttrib('onchange','validateDataType("'.$customerAttributes[$i]['data_type'].'")')

You will need to change onchange="validateDataType(A)" to single quotes... onchange='validateDataType("A")' 您需要将onchange="validateDataType(A)"更改为单引号... onchange='validateDataType("A")'

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

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