2015-03-03 311 views
0

我試圖在使用jQuery進行懸停時更改我的img(s)的src屬性。但我得到一個錯誤的說法,Uncaught SyntaxError: Invalid flags supplied to RegExp constructor 'icon_history'在js.erb文件中提供給RegExp構造函數的無效標誌

app.js.erb

var hover = <%= image_path 'icon_history-h1' %>; 

    var unhover = <%= image_path 'icon_history' %>; 

    $('img.more').hover(function(){ 
    console.log(hover); 
    $(this).attr('src', hover); 
    }, 
    function(){ 
    console.log(unhover); 
    $(this).attr('src', unhover); 
    }); 

回答

1

你應該逃避字符串,並把他們的報價:如果

var hover = '<%= j image_path 'icon_history-h1' %>'; 

var unhover = '<%= j image_path 'icon_history' %>'; 
1

不知道這是你的情況或沒有,但我有類似的問題:

SyntaxError: Invalid flags supplied to RegExp constructor 'u'

我固定它只是在我的Ubuntu服務器更新的Node.js 。 一個版本是:

$ node -v 
v5.1.1 

然後我做:

$ curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash - 
    ... long output 
$ sudo apt-get install -y nodejs 
    ... shorter output 
$ node -v 
v6.7.0 

並沒有更多的問題。

相關問題