我将此代码导入到我的 Ruby on Rails 应用程序中。进口似乎已经成功。但是,当我刷新页面时,我似乎无法克服控制台中弹出的这个错误。更不用说这些代码都不起作用。它应该为明信片边框添加边框颜色。但我不断收到此错误。我哪里走错了?
$(document).on('turbolinks:load', function() {
if ($(".single-post-card").length) {
// set a solid background color style
if (mode == 1) {
$(".single-post-card").each(function() {
$(this).addClass("solid-color-mode");
$(this).css('background-color', randomColor());
});
}
// set a border color style
else {
$(".single-post-card").each(function() {
$(this).addClass("border-color-mode");
$(this).css('border', '5px solid ' + randomColor());
});
}
}
$('#feed').on( 'mouseenter', '.single-post-list', function() {
$(this).css('border-color', randomColor());
});
$('#feed').on( 'mouseleave', '.single-post-list', function() {
$(this).css('border-color', 'rgba(0, 0 , 0, 0.05)');
});
});
var colorSet = randomColorSet();
var mode = Math.floor(Math.random() * 2);
// Randomly returns a color scheme
function randomColorSet() {
var colorSet1 = ['#45CCFF', '#49E83E', '#FFD432', '#E84B30', '#B243FF'];
var colorSet2 = ['#FF6138', '#FFFF9D', '#BEEB9F', '#79BD8F', '#79BD8F'];
var colorSet3 = ['#FCFFF5', '#D1DBBD', '#91AA9D', '#3E606F', '#193441'];
var colorSet4 = ['#004358', '#1F8A70', '#BEDB39', '#FFE11A', '#FD7400'];
var colorSet5 = ['#105B63', '#FFFAD5', '#FFD34E', '#DB9E36', '#BD4932'];
var colorSet6 = ['#04BFBF', '#CAFCD8', '#F7E967', '#A9CF54', '#588F27'];
var colorSet7 = ['#405952', '#9C9B7A', '#FFD393', '#FF974F', '#F54F29'];
var randomSet = [colorSet1, colorSet2, colorSet3, colorSet4, colorSet5, colorSet6, colorSet7];
return randomSet[Math.floor(Math.random() * randomSet.length )];
}
// Randomly returns a color from an array of colors
function randomColor() {
var color = colorSet[Math.floor(Math.random() * colorSet.length)];
return color;
}
错误:
application.js:16 Uncaught Error: Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: /home/maryan/Desktop/workspace/collabfield/app/javascript/posts/style.js: Unexpected token, expected "," (23:4)
21 | $('#feed').on( 'mouseenter', '.single-post-list', function() {
22 | $(this).css('border-color', randomColor());
> 23 | });
| ^
24 |
25 | $('#feed').on( 'mouseleave', '.single-post-list', function() {
26 | $(this).css('border-color', 'rgba(0, 0 , 0, 0.05)');
at Parser._raise (:3000/home/maryan/Desktop/workspace/collabfield/node_modules/@babel/parser/lib/index.js:776)
at Parser.raiseWithData (:3000/home/maryan/Desktop/workspace/collabfield/node_modules/@babel/parser/lib/index.js:769)
at Parser.raise (:3000/home/maryan/Desktop/workspace/collabfield/node_modules/@babel/parser/lib/index.js:737)
at Parser.unexpected (:3000/home/maryan/Desktop/workspace/collabfield/node_modules/@babel/parser/lib/index.js:9735)
at Parser.expect (:3000/home/maryan/Desktop/workspace/collabfield/node_modules/@babel/parser/lib/index.js:9721)
at Parser.parseCallExpressionArguments (:3000/home/maryan/Desktop/workspace/collabfield/node_modules/@babel/parser/lib/index.js:10890)
at Parser.parseCoverCallAndAsyncArrowHead (:3000/home/maryan/Desktop/workspace/collabfield/node_modules/@babel/parser/lib/index.js:10816)
at Parser.parseSubscript (:3000/home/maryan/Desktop/workspace/collabfield/node_modules/@babel/parser/lib/index.js:10752)
at Parser.parseSubscripts (:3000/home/maryan/Desktop/workspace/collabfield/node_modules/@babel/parser/lib/index.js:10725)
at Parser.parseExprSubscripts (:3000/home/maryan/Desktop/workspace/collabfield/node_modules/@babel/parser/lib/index.js:10714)
at Parser.parseUpdate (:3000/home/maryan/Desktop/workspace/collabfield/node_modules/@babel/parser/lib/index.js:10688)
at Parser.parseMaybeUnary (:3000/home/maryan/Desktop/workspace/collabfield/node_modules/@babel/parser/lib/index.js:10666)
at Parser.parseExprOps (:3000/home/maryan/Desktop/workspace/collabfield/node_modules/@babel/parser/lib/index.js:10523)
at Parser.parseMaybeConditional (:3000/home/maryan/Desktop/workspace/collabfield/node_modules/@babel/parser/lib/index.js:10497)
at Parser.parseMaybeAssign (:3000/home/maryan/Desktop/workspace/collabfield/node_modules/@babel/parser/lib/index.js:10460)
at Parser.parseExpressionBase (:3000/home/maryan/Desktop/workspace/collabfield/node_modules/@babel/parser/lib/index.js:10405)
at :3000/home/maryan/Desktop/workspace/collabfield/node_modules/@babel/parser/lib/index.js:10399
at Parser.allowInAnd (:3000/home/maryan/Desktop/workspace/collabfield/node_modules/@babel/parser/lib/index.js:12098)
at Parser.parseExpression (:3000/home/maryan/Desktop/workspace/collabfield/node_modules/@babel/parser/lib/index.js:10399)
at Parser.parseStatementContent (:3000/home/maryan/Desktop/workspace/collabfield/node_modules/@babel/parser/lib/index.js:12390)
at Parser.parseStatement (:3000/home/maryan/Desktop/workspace/collabfield/node_modules/@babel/parser/lib/index.js:12259)
at Parser.parseBlockOrModuleBlockBody (:3000/home/maryan/Desktop/workspace/collabfield/node_modules/@babel/parser/lib/index.js:12845)
at Parser.parseBlockBody (:3000/home/maryan/Desktop/workspace/collabfield/node_modules/@babel/parser/lib/index.js:12836)
at Parser.parseProgram (:3000/home/maryan/Desktop/workspace/collabfield/node_modules/@babel/parser/lib/index.js:12190)
at Parser.parseTopLevel (:3000/home/maryan/Desktop/workspace/collabfield/node_modules/@babel/parser/lib/index.js:12181)
at Parser.parse (:3000/home/maryan/Desktop/workspace/collabfield/node_modules/@babel/parser/lib/index.js:13892)
at parse (:3000/home/maryan/Desktop/workspace/collabfield/node_modules/@babel/parser/lib/index.js:13944)
at parser (:3000/home/maryan/Desktop/workspace/collabfield/node_modules/@babel/core/lib/parser/index.js:54)
at parser.next (<anonymous>)
at normalizeFile (:3000/home/maryan/Desktop/workspace/collabfield/node_modules/@babel/core/lib/transformation/normalize-file.js:55)
at Object../app/javascript/posts/style.js (application.js:16)
at __webpack_require__ (bootstrap:19)
at Module../app/javascript/packs/application.js (application.js:1)
at __webpack_require__ (bootstrap:19)
at bootstrap:83
at bootstrap:83
非常感谢任何帮助。