gpt4 book ai didi

php - 如何在CodeIgniter中动态加载CS、JS?

转载 作者:可可西里 更新时间:2023-11-01 00:41:28 27 4
gpt4 key购买 nike

我有与不同 View 相关的不同 CSS 和 JS 文件。如何根据 View 有条件地或动态地加载CSS和JS,以便只有各自的JS或CSS加载到浏览器?

最佳答案

很简单。只需为您的功能创造条件。然后发送您的 CSS 或 JS 文件位置以供查看。

Controller :

public function index() {
// conditional
if (your condition) {
$this->data = array(
'css' => site_url() . "your css file",
'js' => site_url() . "your js file"
);
} else {
$this->data = array(
'css' => site_url() . "your other css file",
'js' => site_url() . "your other js file"
);
}
$this->load->view('page', $this->data);
}

查看:

<link rel="stylesheet" type="text/css" href="<?php echo $css; ?>">
<script src="<?php echo $js; ?>"></script>

关于php - 如何在CodeIgniter中动态加载CS、JS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35519301/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com