【发布时间】:2015-01-05 09:24:56
【问题描述】:
我正在使用 David Lynch 的 jQuery maphilight (http://davidlynch.org/projects/maphilight/docs/) 来突出显示图像上的图像映射区域。特别是,此演示 (http://davidlynch.org/projects/maphilight/docs/demo_features.html) 展示了如何设置 data-maphilight="{'alwaysOn:true'}" 以使给定的地图区域“始终开启”。
我想根据点击的项目设置“始终开启”。所以我尝试了这个:
$(this).attr('data-maphilight', '{\'alwaysOn\':true}');
使用 Firebug,我可以看到该属性在被点击时被添加到我的元素中,例如:
<area data-county="Susquehanna" href="#" coords="589,62,590,117,518,118,511,62" shape="poly" data-maphilight="{'alwaysOn':true}">
但是,该元素没有保持突出显示。
如果我手动(在 HTML 标记中)设置 alwaysOn,像这样:
<area shape="poly" coords="447,193,442,225,453,222,467,226,467,235,472,235,475,242,486,242,489,251,448,268,420,276,433,257,434,246,438,235,428,220,433,206,430,194,438,191" href="#" data-county="Northumberland" data-maphilight='{"alwaysOn":true}'>
...它确实有效。这是单引号和双引号的混合吗?当我使用 jQuery "attr" 语句时,它会自动使用双引号,所以我不得不反转它们。或者,这是一个仅设置该属性不会导致 jQuery 插件更新的问题吗?
如果我尝试修改此脚本以执行我想要的操作,我将不胜感激。
谢谢!
【问题讨论】:
标签: javascript jquery