【问题标题】:Issue when trying to load image via .load尝试通过 .load 加载图像时出现问题
【发布时间】:2011-10-21 20:22:27
【问题描述】:

我在下面有一个 html 页面,其中有一个名为 #fullInfo 的部分。我想要做的是拥有它,这样当用户单击图像地图的区域时,它会将一些数据拉入#fullInfo div。

我正在尝试遵循本教程http://net.tutsplus.com/tutorials/javascript-ajax/how-to-load-in-and-animate-content-with-jquery/。

我遇到的问题是,当您单击图像地图的某个区域时,它只会将您直接带到 url,而不是将其加载到 #fullInfo div 中。

任何想法我做错了什么?

这是我的 html 页面:

<!DOCTYPE HTML>

<html>

<head>
<style>

#content {
    width: 960px;
    margin: 0 auto;
    background: #c7c7c7;
    border: solid 1px #dcdcdc;
    overflow: hidden;
}
#main {
    width: 484px;
    float: left;
}
#sidebar {
    width: 400px;
    float: left;
    background: #e7e7e7;
    overflow: hidden;
}
#sidebar img {
    width: 200px;
    height: 200px;
}
#info {

}
#load {  
    display: none;  
    position: absolute;  
    rightright: 10px;  
    top: 10px;  
    background-color: red;  
    width: 43px;  
    height: 11px;  
    text-indent: -9999em;  
}  

</style>
<script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js”></script>
<script type="text/javascript">
$(document).ready(function() {

    $('area').click(function() {

        var toLoad = $(this).attr('href');
        console.log('toLoad = '+toLoad);
        $('#fullInfo').hide('fast', loadContent);
        $('#load').remove();
        $('#main').append('<span id="load">Loading...</span>');
        $('#load').fadeIn('normal');

        function loadContent() {
            $('#fullInfo').load(toLoad, '', showNewContent());
        }
        function showNewContent() {
            $('#fullInfo').show('normal', hideLoader());
        }
        function hideLoader() {
            $('#load').fadeOut('normal');
        }

        return false;   // used so the link does take you to a new page
    });

});
</script>
</head>

<body>

    <div id="content">

        <div id="main">
            <!-- <img src=floorPlan.jpg /> -->
            <div style="text-align:center; width:484px; margin-left:auto; margin-right:auto;">
                <img id="Image-Maps_4201110211433362" src="http://www.image-maps.com/uploaded_files/4201110211433362_floorPlan.jpg" usemap="#Image-Maps_4201110211433362" border="0" width="484" height="480" alt="" />
                <map id="_Image-Maps_4201110211433362" name="Image-Maps_4201110211433362">
                    <area shape="rect" id="1" coords="68,35,139,85" href="http://www.google.com/logos/2011/mary_blair-2011-hp.jpg" alt="Meeting Room 200" title="Meeting Room 200" />

                </map>

                <!-- Image map text links - Start - If you do not wish to have text links under your image map, you can move or delete this DIV -->
                <div style="text-align:center; font-size:12px; font-family:verdana; margin-left:auto; margin-right:auto; width:484px;">
                    <a style="text-decoration:none; color:black; font-size:12px; font-family:verdana;" href="http://www.image-maps.com/" title="Meeting Room 200">Meeting Room 200</a>
                |   
                </div>
                <!-- Image map text links - End - -->

            </div>

        </div>

        <div id="sidebar">

            <div id="fullInfo">

                <img src="floorPlan.jpg" />

                <div id="info">
                    <h3>Some text here</h3>
                    <p>This is a paragraph about something or other here</p>

                    <p><a href="http://google.com title=Google">This here our link text</a></p>
                </div>

            </div>

        </div>

    </div>

</body>

</html>

【问题讨论】:

  • 您可以使用jsfiddle.net 发布大量这样的示例代码。它更容易阅读和测试。 :)

标签: jquery load imagemap


【解决方案1】:
<script type="text/javascrtip">
$('area').click(function() {

改成

<script type="text/javascript">
$('area').click(function(e) {
    e.preventDefault();

【讨论】:

  • 它仍然将我带到实际页面,而不是在我更改之后将其引入。
  • jsfiddle.net/P573q/4 似乎还有其他问题,但它没有导航到该链接。检查 javascript 错误。也许脚本根本没有运行,因为text/javascrtip(错字)
  • 我实际上在一秒钟前更改了该文本/javascript,但它仍然无法正常工作。
  • 它在小提琴中工作。不知道还能说什么。您是否收到 javascript 错误?
  • 好的,现在我看到我收到了$ is not defined。
猜你喜欢
  • 2021-05-19
  • 1970-01-01
  • 1970-01-01
  • 2011-06-20
  • 2011-12-31
  • 2013-02-23
  • 1970-01-01
  • 1970-01-01
  • 2013-07-09
相关资源
最近更新 更多