我正在使用onMouseOver和onMouseOut函数来更改Wordpress网站页脚中某些社交媒体图标的颜色:http://www.retelevise.com。
它工作正常,但我也使用一段Javascript链接到我的电子邮件地址(我在某处读到这是隐藏垃圾邮件发送者地址的好方法吗?) - 但Javascript似乎没有喜欢鼠标功能。
<script type="text/javascript">
<!--
var addr1 = "mailto:"
var addr2 = "info"
var addr3 = "@"
var addr4 = "retelevise"
var addr5 = ".com"
document.write('<a href="' + addr1 + addr2 + addr3 + addr4 + addr5 + '">')
document.write('<img src="http://www.retelevise.com/wp-content/themes/myownzee/branding/socialmedia-email-1.png" onmouseover="this.src='http://www.retelevise.com/wp-content/themes/myownzee/branding/socialmedia-email-2.png'" onmouseout="this.src='http://www.retelevise.com/wp-content/themes/myownzee/branding/socialmedia-email-1.png'" class="social-icons-main" title="Email" alt="Email"></a>');
//-->
</script>
如果我删除鼠标功能,只显示灰色电子邮件图标而不会在悬停时切换到彩色版本,但是当我尝试添加鼠标代码时,电子邮件图标完全消失。我确实看过这里发布的一些类似答案,但很遗憾我不理解他们。有人有什么想法吗?
谢谢, SN。
答案 0 :(得分:1)
单个引用值中没有使用单引号的转义。
http://jsbin.com/nakoduqa/1/edit
var addr1 = "mailto:"
var addr2 = "info"
var addr3 = "@"
var addr4 = "retelevise"
var addr5 = ".com"
document.write('<a href="' + addr1 + addr2 + addr3 + addr4 + addr5 + '">')
document.write('<img src="http://www.retelevise.com/wp-content/themes/myownzee/branding/socialmedia-email-1.png" onmouseover="this.src=\'http://www.retelevise.com/wp-content/themes/myownzee/branding/socialmedia-email-2.png\'" onmouseout="this.src=\'http://www.retelevise.com/wp-content/themes/myownzee/branding/socialmedia-email-1.png\'" class="social-icons-main" title="Email" alt="Email"></a>');