未捕获的ReferenceError:bind()赋值的左侧无效

时间:2018-02-02 18:59:17

标签: javascript jquery

我正在尝试将监听器附加到我的视频以更新某些自定义控件的输入范围,并且收到的错误显示为Uncaught ReferenceError: Invalid left-hand side in assignment

$(document).on('click', '.play-pause', function() {
    const video = $(this).closest('.video-container').children('video').get(0);
    if (video.paused == true) {
        video.play();

        $(this).closest('.video-container').children('video').bind('timeupdate', function() {
            let value = (100 / video.duration) * video.currentTime;
            $(this).closest('.video-container').find('.seek-bar').val() = value;
        })

        $(this).children('svg').remove();
        $(this).html(
            `<i class="fas fa-pause fa-fw"></i>`
        );
    } else {
        video.pause();
        $(this).children('svg').remove();
        $(this).html(
            `<i class="fas fa-play fa-fw"></i>`
        );
    }
});

2 个答案:

答案 0 :(得分:2)

这不是你如何在jQuery中为元素设置值:

$(this).closest('.video-container').find('.seek-bar').val() = value;

This is

$(this).closest('.video-container').find('.seek-bar').val(value);

如错误所述,您不能使用函数调用作为变量赋值的目标。您可以为变量赋值,而不是为函数赋值。

答案 1 :(得分:1)

如果要使用赋值运算符赋值,则需要使用plain js ..

$(this).closest('.video-container').find('.seek-bar')[0].value = value;

您只能为变量或属性赋值,因为您尝试将值分配给函数val() = value

的输出而得到该错误