【问题标题】:undefined is not a function in maphilight.jsundefined 不是 maphilight.js 中的函数
【发布时间】:2014-09-06 12:29:53
【问题描述】:

我在使用看似简单的插件时遇到了问题:https://github.com/kemayo/maphilight

我尝试了无数的事情,并不断从我在 main.js 中的一行代码中得到:Uncaught TypeError: undefined is not a function

我正在使用最新的稳定版本的 jquery 和 maphilight。

main.html:

<body>
    <img class="img_map" usemap="#regional_map">
    <map name="regional_map">
        <area ...... />
        <area ...... />
    </map>

    <script src="js/jquery-1.11.1.min.js" type="text/javascript"></script>
    <script src="js/jquery.maphilight.js" type="text/html"></script>
    <script src="js/main.js" type="text/javascript"></script>  
</body>

main.js:

$(".img_map").maphilight();

【问题讨论】:

标签: javascript jquery imagemap


【解决方案1】:

您正在使用text/html 包含您的maphilight javascript 文件。试试这个:

<script src="js/jquery.maphilight.js" type="text/javascript"></script>

【讨论】:

    【解决方案2】:

    a) 我强烈建议将您的脚本标签包含在:

    <head></head>
    

    b) 在你的 main.js 中试试这个:

    $(function() {
        $('.img_map').maphilight();
    });
    

    c) 这在你的 html 中:

    <img class="img_map"></img>
    

    【讨论】:

    • 实际上是从正文标签末尾加载脚本的好习惯,以便更快地加载其他资源
    • 我明白这一点,但尤其是当您刚刚进行设置时,最好以安全的方式进行所有操作。设置演示后,您可以逐步更改它。它有助于避免由于我们遗漏小细节而发生的小错误。
    猜你喜欢
    • 2014-09-29
    • 1970-01-01
    • 2020-10-12
    • 2015-10-29
    • 2015-06-05
    • 2019-10-16
    • 2015-06-12
    • 2015-10-16
    • 2013-05-17
    相关资源
    最近更新 更多