duanqiang6501 2012-12-05 22:45
浏览 37
已采纳

jQuery Mapster与来自php的动态数据

We are building a website and for that we need to include an image map from a country and when you highlight a provence it needs to show some content below the map.

For this we are using jquery mapster (I'm not really a jquery programmer, so maybe you could help).

All works with the code below, but only when the content is on 1 line.

For example groningen: "<h1>Groningen</h1><p>test</test>", <-- This works

For example

groningen: "<h1>Groningen</h1>
<p>test</test>",

This does not work.

Below you will find my jquery code

<script type="text/javascript">
var $s = jQuery.noConflict(); 
$s(document).ready(function () {
       var image = $s('img');
       var data = {
            groningen: "<h1>Groningen</h1>
<p>test</test>",
            friesland: "<?php echo $extrafields[10];?>",
       };
       var defaultDipTooltip = 'I know you want the dip. But it\'s loaded with saturated fat, just skip it and enjoy as many delicious, crisp vegetables as you can eat.';

       image.mapster(
       {
            fillOpacity: 1,
            fillColor: "ff2d52",
            strokeColor: "ff2d52",
            strokeOpacity: 0.8,
            strokeWidth: 1,
            stroke: true,
            isSelectable: true,
            singleSelect: true,
            mapKey: 'name',
            listKey: 'name',
            onClick: function (e) {
                var newToolTip = defaultDipTooltip;
                $s('#selections').html(data[e.key]);
                if (e.key==='asparagus') {
                    newToolTip = "OK. I know I have come down on the dip before, but let's be real. Raw asparagus without any of that " +
                            "delicious ranch and onion dressing slathered all over it is not so good.";
                }
                image.mapster('set_options',{areas: [{
                    key: "dip",
                    toolTip: newToolTip
                    }]
                });
            },
            showToolTip: true,
            toolTipClose: ["tooltip-click", "area-click"],
            areas: [
                {
                    key: "groningen",
                    fillColor: "ff2d52",
                    toolTip: defaultDipTooltip
                },
                {
                    key: "friesland",
                    fillColor: "ff2d52"
                }
                ]
        });
      });
      </script>

Output

var data = {
    groningen: "<h1>Groningen</h1><p>test</test>",
    friesland: "<p>Scholen in de regio Groningen</p>
    
<ul>
    
<li>AOC Terra, Groene school<br />Adres<br />Winsum<br />Telefoonnummer<br />Naam directeur</li>
    
<li>De Bolster<br />Adres<br />Groningen<br />Telefoonnummer<br />Naam directeur</li>
    
<li>De Catamaran, School voor Praktijkonderwijs<br />Adres<br />Stadskanaal<br />telefoonnummer<br />Naam directeur</li>
    
<li>Dollard College locatie De Flint</li>
    
</ul>",
    }; 
  • 写回答

1条回答 默认 最新

  • dongzhong3688 2012-12-05 22:53
    关注

    Javascript and by extension jQuery strings cannot go over a line boundry, you need to either add 2 strings together with a + or replace newlines with

    Do some manipulation of your php array so each newline is replaced with

    $UpdatedString = str_replace("
    ", '\
    ', $FieldValue);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题