When I define a function in Yii view
Yii::app()->clientScript->registerScript('jqeury5',
"function fn(){ alert('hello'); }"
);
then try to call it, the Firebug says the “fn isn’t defined” when I press on button.
<input type="button" value="Display alert box in 3 seconds"
onclick="fn()" />
Put the function in the
<head>part, or<body>part of the html document that is generated. Use the third parameter of theregisterScript()function.So your code will be:
For more details read the api documentation here.
P.S: i think by default the script is inserted in jQuery’s
readyfunction. Hence the function is not detected.