Javascript 为js.erb文件中的RegExp构造函数提供的标志无效
当img使用jQuery悬停在上方时,我试图更改img的Javascript 为js.erb文件中的RegExp构造函数提供的标志无效,javascript,jquery,ruby-on-rails,erb,Javascript,Jquery,Ruby On Rails,Erb,当img使用jQuery悬停在上方时,我试图更改img的src属性。但是我得到一个错误,它是,uncaughtsyntaxerror:RegExp构造函数'icon\u history'提供的标志无效。 app.js.erb var hover = <%= image_path 'icon_history-h1' %>; var unhover = <%= image_path 'icon_history' %>; $('img.more').hover(f
src
属性。但是我得到一个错误,它是,uncaughtsyntaxerror:RegExp构造函数'icon\u history'提供的标志无效。
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);
});
var hover=;
var unhover=;
$('img.more').hover(函数(){
console.log(悬停);
$(this.attr('src',hover);
},
函数(){
控制台日志(unhover);
$(this.attr('src',unhover);
});
您应该转义字符串并将其置于引号中:
var hover = '<%= j image_path 'icon_history-h1' %>';
var unhover = '<%= j image_path 'icon_history' %>';
var hover='';
var unhover='';
不确定这是否是您的情况,但我有类似的问题:
SyntaxError:提供给RegExp构造函数“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
没有其他问题了