gpt4 book ai didi

javascript - 无法弄清楚是什么导致了意外的 token 错误

转载 作者:行者123 更新时间:2023-11-28 20:27:46 27 4
gpt4 key购买 nike

我在控制台中收到此错误

SyntaxError: Unexpected token '(' ... line 49

这是有问题的行:

 trackEnded: function() {

这是完整的代码,我只是不明白为什么会收到该错误?

// Initialize audio js
$(document).ready(function($) {


// Setup the player to autoplay the next track
trackEnded: function() {
var next = $('.main article.playing').next();
if (!next.length) next = $('.main article').first();
next.addClass('playing').siblings().removeClass('playing');
audio.load($('.article-play', next).attr('data-src'));
audio.play();
$('.article-play', next).removeAttr('data-playa').attr("data-pausea", '5');
var nextPlay = $('.article-play', next);
$('.article-play').not(nextPlay).removeAttr('data-pausea').attr("data-playa", '4');
}


//Synchronize Main player with articles
$(".audiojs .play-pause").click(function() {
var element = $('.playing .article-play')
var play = element.attr('data-playa')
var pause = element.attr('data-pausea')
if (play == '4') {
element.removeAttr('data-playa').attr("data-pausea", '5');
} else if (pause == '5') {
element.removeAttr('data-pausea').attr("data-playa", '4');
}
})

// Load in a track on click
$('.article-play').click(function(e) {
e.preventDefault();
if ($(this).closest('article').hasClass('playing')) {
var play = $(this).attr('data-playa')
var pause = $(this).attr('data-pausea')
if (play == '4') {
$(this).removeAttr('data-playa').attr("data-pausea", '5');
$('.article-play').not($(this)).removeAttr('data-pausea').attr("data-playa", '4');
audio.play();
} else if (pause == '5') {
$(this).removeAttr('data-pausea').attr("data-playa", '4');
audio.pause();
}
} else {
$(this).closest('article').addClass('playing').siblings().removeClass('playing');
audio.load($(this).attr('data-src'));
audio.play();
$(this).removeAttr('data-playa').attr("data-pausea", '5');
$('.article-play').not($(this)).removeAttr('data-pausea').attr("data-playa", '4');
}
});

// Keyboard shortcuts
$(document).keydown(function(e) {
var unicode = e.charCode ? e.charCode : e.keyCode;
// right arrow
if (unicode == 39) {
var next = $('.main article.playing').next();
if (!next.length) next = $('.main article').first();
next.find('.article-play').click();
// back arrow
} else if (unicode == 37) {
var prev = $('.main article.playing').prev();
if (!prev.length) prev = $('.main article').last();
prev.find('.article-play').click();
// spacebar
} else if (unicode == 32 && document.activeElement.nodeName !== 'INPUT') {
audio.playPause();
var element = $('.playing .article-play')
var play = element.attr('data-playa')
var pause = element.attr('data-pausea')
if (play == '4') {
element.removeAttr('data-playa').attr("data-pausea", '5');
} else if (pause == '5') {
element.removeAttr('data-pausea').attr("data-playa", '4');
}
}
});
});

最佳答案

您试图在函数作用域内编写对象语法,这是不正确的语法。

应该是:

function trackEnded() {
// rest or your code

关于javascript - 无法弄清楚是什么导致了意外的 token 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17046664/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com