0
我想要在Rails视图中使用CoffeeScript在链接mouseover上更新简单图像src。CoffeeScript在鼠标悬停上更改图像src
出于某种原因,这工作得很好:
showimghover = (imgpath) ->
$('.thelink').mouseover ->
imgpath = '../../images/imagefile.jpg'
$("#theimage").attr
src: '../../images/imagefile.jpg'
但由于某些原因,当我在字符串变量插入手写的URL,而不是这不会更新IMG SRC:
showimghover = (imgpath) ->
$('.thelink').mouseover ->
imgpath = '../../images/imagefile.jpg'
$("#theimage").attr
src: imgpath
编辑:
为了澄清这一问题,这工作得很好:
$('#imghover').css('background','url(../../images/imagefile.jpg)')
但是,当插入一个变量,它不工作:
imgpath = 'url(../../images/imagefile.jpg)'
$('#imghover').css('background', imgpath)
你能告诉我们你是如何调用showimghover功能的吗? – Mario