首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > PHP >

CI中怎么让js调用php中的变量

2012-08-14 
CI中如何让js调用php中的变量控制器:class Index extends CI_Controller{// 构造函数function __construct

CI中如何让js调用php中的变量
控制器:

class Index extends CI_Controller
{  
 // 构造函数
 function __construct()
 {
  parent::__construct();
  
  // 载入url类和模板解析类
  $this->load->helper('url');
  $this->load->library('parser');
 }
 
 // 首页(默认展现合肥地区)
 function index($locat = 'hf')
 {  
  $data = array(
  'locat' => $locat,
  );

  $this->parser->parse('index', $data);
 }
}


view下index.php中有一段js,想调用$locat变量的值


jQuery(function($){
 $("#count_p").parent("div").hide(); //消除
 $("#menu #$locat").attr("class", "selected");
});


这么写无法实现,该怎么写才行?望高手指教

[解决办法]
// 首页(默认展现合肥地区)
 function index($locat = 'hf')
 {
$data['locat'] = $locat;

$this->parser->parse('index', $data);
 }


view 里面js里面 var a = <?php echo $locat; ?>;

热点排行