我是CakePhp和JQuery的新手.我在使用JQuery中的cakephp代码时遇到错误.
我的代码
<script type="text/javascript">
$(document).ready(function(){
var attributeid;var fieldname;
$("#"+<?=$r['Attribute']['id'];?>).change(function () {
fieldname=<?=$r['Attribute']['label'];?>;
alert(fieldname);//this show me that undefined
attributeid=<?=$r['Attribute']['id'];?>;
alert(attributeid);//But this works
});//attribute change
});//ready function
Run Code Online (Sandbox Code Playgroud)
如果我回应($r['Attribute']['label'];)这个价值就在我的内心<?php ?>.但不是在我的JQuery中.
注意 :
attributeid=<?=$r['Attribute']['id'];?>;
alert(attributeid);//But this works
Error:
Name is not defined
fieldname=name;
alert(fieldname);
Run Code Online (Sandbox Code Playgroud)