js.erb文件中提供给RegExp构造函数的标志无效
Invalid flags supplied to RegExp constructor in js.erb file
当img悬停在jQuery上时,我正试图更改它们的src
属性。但我收到一个错误,说Uncaught SyntaxError: Invalid flags supplied to RegExp constructor 'icon_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 = '<%= j image_path 'icon_history-h1' %>';
var unhover = '<%= j image_path 'icon_history' %>';
不确定是否是您的情况,但我遇到了类似的问题:
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
没有更多的问题。
相关文章:
- ES6构造函数返回基类的实例
- 使用Google Visualization动态调用构造函数
- javascript中对象构造函数中的var属性与this.properties
- 理解typescript中的构造函数接口
- 为什么构造函数不是构造函数
- 如果在构造函数中有“返回”,则在 JavaScript 中的新运算符中做了什么
- 拦截对构造函数的调用
- 使用闭包共享构造函数参数
- 文本表示法VS.构造函数,用于在JavaScript中创建对象
- 从js引擎的角度来看闭包和构造函数是如何工作的
- js.erb文件中提供给RegExp构造函数的标志无效
- Javascript RegExp 与构造函数和文字不同的结果
- 使用RegExp构造函数的具有可变模式的JavaScript正则表达式
- 防止在JavaScript中污染RegExp构造函数的属性
- 何时使用RegExp构造函数vs正则表达式文本
- RegExp构造函数属性输入
- 通过对象匹配Javascript regexp中的空白,通过regexp构造函数创建
- 未捕获的SyntaxError:提供给RegExp构造函数的无效标志'usuario'
- 匹配字符串“/$"在RegExp构造函数中
- 未捕获的SyntaxError:提供给RegExp构造函数的无效标志''