简体   繁体   English

允许轻松添加Javascript onclick事件的Image Map Creator / Generator?

[英]Image Map Creator/Generator that allows for the easy addition Javascript onclick events?

While I'm well aware of how image maps work, and how to code them, etc...I find it a waste of time to use the image map creator to generate the Image Map code, then use HTML Tidy to tidy it, and then manually add all of the image attribute adding onclick events, having them return false, and making sure that the href="#", especially for large image maps. 虽然我很了解图像映射的工作原理以及如何编码等等,但是我发现浪费时间使用图像映射创建器来生成图像映射代码,然后使用HTML Tidy进行整理,然后手动添加所有图像属性,并添加onclick事件,使它们返回false,并确保href =“#”,特别是对于大型图像地图。

Does anyone know of an image map creator that supports adding Javascript events (such as onclick) directly as opposed to just adding href urls, and then having to manual edit the code later? 有谁知道图像地图创建者支持直接添加Javascript事件(例如onclick),而不是仅添加href网址,然后在以后手动编辑代码?

You're trying to solve this problem the wrong way. 您正在尝试以错误的方式解决此问题。 This problem has nothing to do with creating image maps, it has to do with manipulating HTML. 这个问题与创建图像映射无关,与处理HTML无关。 There's nothing unique about the tags in an imagemap. 图像映射中的标签没有什么独特之处。

So you have a bunch of stuff you want to do to some HTML, which happens to be an imagemap. 因此,您需要对HTML进行很多处理,这些HTML恰好是图像映射。 Why not use something designed specifically to manipulate HTML, eg jQuery, to solve your problem? 为什么不使用专门设计用于处理HTML的东西(例如jQuery)来解决您的问题?

"adding onclick events, having them return false, and making sure that the href="#"... “添加onclick事件,使它们返回false,并确保href =“#” ...

$('area').attr('href','#');
$('area').attr('onclick','.. whatever you want ...');

Just because jQuery is a javascript tool doesn't mean you can't use it for one-time tasks. 仅仅因为jQuery是一种javascript工具,并不意味着您不能将其用于一次性任务。 Right click in Chrome, inspect element, "Copy as HTML." 在Chrome中右键单击,检查元素“复制为HTML”。

Now let me add that using jQuery to add onclick attributes makes little sense, generally, since you should just be adding event handlers. 现在让我补充一点,通常来说,使用jQuery添加onclick属性毫无意义,因为您应该只添加事件处理程序。 But you could do this if you wanted to produce HTML that you will then copy/paste as hardcoded HTML. 但是,如果您想生成HTML,然后将其复制/粘贴为硬编码HTML,则可以执行此操作。 But I generally speaking, "onclick" should be avoided like the plague, especially with (as you say) imagemaps that have a lot of elements. 但是我一般来说,应该避免像瘟疫一样发生“ onclick”事件,尤其是(如您所说)包含大量元素的图像映射。 It's just wasted bandwidth; 这只是浪费带宽; since you're binding javascript handlers anyway you are obviously running javascript on your page already. 因为无论如何绑定javascript处理程序,您显然已经在页面上运行了javascript。 Why not just use javascript to bind the handlers? 为什么不只使用javascript绑定处理程序?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM