简体   繁体   English

我应该把Javascript放在哪里?

[英]Where should I put my Javascript in Wordpress?

Okai so i have this worldmap in on of my wordpress pages and have for example this code Okai,所以我在wordpress页面上有这个世界地图,例如有此代码

<area onmousedown="changeImages('world_leisureCargo_01', './images/worldmap/north_america.jpg')" onmouseout="changeImages('world_leisureCargo_01', './images/worldmap/world.jpg')" onmouseover="changeImages('world_leisureCargo_01', './images/worldmap/north_america.jpg')" coords="121,72,155,45,202,46,248,35,289,27,340,44,352,54,336,69,349,93,342,110,261,159,261,177,240,162,220,168,213,187,218,198,233,189,235,202,244,211,249,225,241,225,216,206,190,195,171,171,159,130,172,111,178,78,154,68,132,79" href="#" alt="North America" shape="poly"> 

What this code does is change to another images when hovering over certain part of the map by using the function changeImage.. The problem is i cant have the function which is like this 此代码的作用是通过使用changeImage函数将鼠标悬停在地图的某些部分上时更改为另一幅图像。问题是我无法拥有像这样的函数

<script type="text/javascript">

function changeImages() {
if (document.images && (preloadFlag == true)) {
for (var i=0; i<changeImages.arguments.length; i+=2) {
document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
}
}

below the html code because wordpress seems to "sugar-code" some part of it so it doesnt work. 在html代码下方,因为wordpress似乎对其部分内容进行了“糖编码”,因此无法正常工作。

Where should i put the Javascript code then so it works ? 我应该将Javascript代码放在哪里,然后使其起作用?

Here is an example of how I added it in a site I built for a client. 这是我如何在为客户构建的网站中添加它的示例。 I had a hard time including it externally, so I ended up just using the editor to place the images. 我很难在外部包括它,所以最终我只是使用编辑器放置图像。 I use TinyMce Advanced (I'm not sure if the regular editor would strip out the formatting, but it works with TinyMce Advanced): 我使用TinyMce Advanced(我不确定常规编辑器是否会去除格式,但它可与TinyMce Advanced一起使用):

  <p style="text-align: center;">
    <a title="Other Notable Projects" href="http://www.amasonry.com/other-notable-projects/">
    <img class="alignnone" onmouseover="this.src='http://www.amasonry.com/wp-content/themes/infocus/images/Sonic-Headquarters-Sepia.jpg';" onmouseout="this.src='http://www.amasonry.com/wp-content/themes/infocus/images/Sonic-Headquarters-Color.jpg';" src="http://www.amasonry.com/wp-content/themes/infocus/images/Sonic-Headquarters-Color.jpg" alt="" width="375" height="205" />
    </a>
  </p>

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

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