【问题标题】:how to insert div directly in tag href area shape如何在标签href区域形状中直接插入div
【发布时间】:2014-02-06 15:23:37
【问题描述】:

我想知道是否可以插入以下div

<div id="cal1"> [dopbsp id="1"  lang=it]</div>

<div id="cal2"> [dopbsp id="1"  lang=it]</div>

<div id="cal3"> [dopbsp id="1"  lang=it]</div>

直接在标签href中不同形状区域链接的图片映射如下

<area shape="circle" coords="160,59,20" href="#">
<area shape="circle" coords="111,58,20" href="#">
<area shape="circle" coords="60,59,20"  href="#">

这样当我点击形状区域时,例如

<area shape="circle" coords="160,59,20" href="#">

然后是对应的div,例如

<div id="cal1"> [dopbsp id="1"  lang=it]</div>

在地图图片下加载 ps:dopbsp id="1" ...是wordpress的日历预约插件

谢谢

【问题讨论】:

    标签: javascript css map shape area


    【解决方案1】:

    你不能。 &lt;area&gt; 不能有任何子元素。有关详细信息,请参阅区域标签上的 World-wide Web compendium working draft 或 Mozilla Developer Network description。

    执行此操作的方法是通过 ID 将给定的 &lt;area&gt; 与给定的 &lt;div&gt; 连接起来,并在您单击 &lt;area&gt; 时使用 JavaScript 显示/隐藏 &lt;div&gt;。大致如下:

    <area shape="circle" coords="160,59,20" href="#id-of-div-1">
    <area shape="circle" coords="111,58,20" href="#id-of-div-2">
    <area shape="circle" coords="60,59,20"  href="#id-of-div-3">
    
    <div class="divs-to-show-hide">
     <div id="id-of-div-1">some content here</div>
     <div id="id-of-div-2">some content here</div>
     <div id="id-of-div-3">some content here</div>
    </div>
    

    jQuery

    $('area').on('click',function(e) {
     e.preventDefault();
     $(this.href).show().siblings().hide();
    });
    

    【讨论】:

    • 不是$($(this).attr('href')).show().siblings().hide();吗?
    • @krlzlx - $(this).attr('href') === this.href..... 这个答案也是从 2014 年开始的,所以如果今天使用它是 YMMV
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-28
    • 2021-02-07
    • 1970-01-01
    • 2014-02-07
    • 1970-01-01
    相关资源
    最近更新 更多