【问题标题】:Why am I unable to acces external javascript files using codeigniter even though they get loaded?为什么我无法使用 codeigniter 访问外部 javascript 文件,即使它们已加载?
【发布时间】:2013-09-21 05:14:04
【问题描述】:

我的项目结合使用 Bootstrap 和 Codeigniter。我无法访问外部 javascript 文件中的函数。在 Firefox 中使用 firebug 我可以看到这些外部脚本被加载。外部 css 文件工作正常。请注意 jquery 可以工作,但我怀疑这是因为 jquery.js 文件包含在目录 assets/js/jquery.js 中的 Bootstrap/Codeigniter 框架中

这是我在每个 Codeigniter 视图中的标头代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <!-- Fav and touch icons -->
    <link rel="apple-touch-icon-precomposed" sizes="144x144" href="/img/icons/apple-touch-icon-144-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="114x114" href="/img/icons/apple-touch-icon-114-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="72x72" href="/img/icons/apple-touch-icon-72-precomposed.png">
    <link rel="apple-touch-icon-precomposed" href="/img/icons/apple-touch-icon-57-precomposed.png">
    <link rel="shortcut icon" href="/img/icons/favicon.png">

    <title>Sample Website</title>

    <!-- Bootstrap core CSS -->
    <link href="/dist/css/bootstrap.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="../../assets/js/html5shiv.js"></script>
      <script src="../../assets/js/respond.min.js"></script>
    <![endif]-->

    <!-- Custom styles for this template -->
    <link href="/css/theme.css" rel="stylesheet">
    <link href="/css/carousel.css" rel="stylesheet">

    <!-- styles custom to our site -->
    <link href="/css/style.css" rel="stylesheet">

    <link href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" rel="stylesheet">
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>        
    <script type="text/javascript" src="js/jquery.cookie.js"></script>   

</head>

【问题讨论】:

  • 您只有3 jQuery 文件,而您提到jQuery 有效,那么还有什么?
  • &lt;!--[if lt IE 9]&gt; 之间?
  • &lt;script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"&gt;&lt;/script&gt;--&gt; 这是错字吗?
  • 是的,将其输入问题框是一个错字...我删除了它
  • css 和 Jquery 有效,但 JQuery UI 和 jquery cookie 无效...我已经尝试过另一个外部 javascript 文件,但只有将文件的内容复制到当前页面时它才会有效跨度>

标签: javascript jquery jquery-ui codeigniter


【解决方案1】:

尝试在url前加上base_url:

<script type="text/javascript" src="<?= base_url();?>js/jquery.cookie.js"></script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-12
    • 1970-01-01
    • 1970-01-01
    • 2022-12-26
    • 2013-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多