Home >Backend Development >PHP Tutorial >CI中怎么让js调用php中的变量

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

WBOY
WBOYOriginal
2016-06-13 10:34:12995browse

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 = ;

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn