相关疑难解决方法(0)

在CakePHP视图中呈现jQuery代码时,如何将PHP变量用作<script>标记的值?

我是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)

javascript php jquery cakephp

0
推荐指数
1
解决办法
454
查看次数

标签 统计

cakephp ×1

javascript ×1

jquery ×1

php ×1