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