为什么它在控制台中向我输出这个:Uncaught SyntaxError: Unexpected end of input

问题描述 投票:0回答:1

当我尝试使用按钮播放视频时,出现错误 Uncaught SyntaxError: Unexpected end of input 我无法弄清楚原因可能是什么,因为我对 JavaScript 还很陌生,这是我的 JS 代码:

let GettedVideo
const Video_player = document.getElementById('vidplay');

 $(window).on('load', function(){
    var fileExt = ".mp4";
 
         $(document).ready(function(){
 
             $.ajax({
                 //This will retrieve the contents of the folder if the folder is configured as 'browsable'
                 url: 'content/videos',
                 success: function (data) {
                     console.log(data);
                    $("#fileNames").html('<ul>');
                    //List all xml file names in the page
 
                     //var filename = this.href.replace(window.location, "").replace("http:///", "");
                    //$("#fileNames").append( '<li>'+filename+'</li>');
 
                     $(data).find("a:contains(" + fileExt + ")").each(function () {
                        var sa = '"PlayVideo("'+ $(this).text() + '")"';
                        console.log(sa)
                         $("#fileNames").append( '<div class="inDiv"<li>'+$(this).text()+ ' '+' </li><button onclick='+ sa +'><i class="fa-solid fa-play"></i> Play</button></div>');
                         GettedVideo = $(this).text()
                         console.log(GettedVideo)
                     });
                     $("#fileNames").append('</ul>');
                 }
             });
 
         });
 });

function PlayVideo(targetVideoName) {
    var videoPath = "content/videos/" + targetVideoName;
    console.log(videoPath);
    Video_player.src = videoPath;
    Video_player.load();
    Video_player.play();
    console.log('Video '+ videoPath + ' Playing...');
};
 

这是我的 HTML:

<!DOCTYPE html>
<html>
    <head>
        <title>kd</title>
        <link rel="stylesheet" href="assets/style/style.css">
        <link rel="stylesheet" href="assets/icons/fontawesome-free-6.6.0-web/css/fontawesome.min.css">
        <link rel="stylesheet" href="assets/icons/fontawesome-free-6.6.0-web/css/fontawesome.css">
        <link rel="stylesheet" href="assets/icons/fontawesome-free-6.6.0-web/css/all.css">
        <link rel="stylesheet" href="assets/icons/fontawesome-free-6.6.0-web/css/all.min.css">
    </head>
    <body>
        
        <div class="elementsBackround">
        <div class="videoDiv"><video controls class="vidCon" id="vidplay">
            <source id="source" src="">
        </video></div>
        
        <h1>Video List:</h1>
        <div class="divElements" id='fileNames'></div>
        </div>
        <script src=" https://code.jquery.com/jquery-3.2.1.min.js"></script>
        <script src="assets/scripts/VideoGet.js" type="text/javascript">//<![CDATA[ </script>
    </body>
</html>

我想通过单击列表中的按钮来使视频以 mp4 格式播放,但错误是 Uncaught SyntaxError: Unexpected end of input 请帮我解决这个问题

我也无法弄清楚这个错误发生在哪一行,因为错误中没有指定代码行

I tried to look for a solution to this problem on stack overflow but I did not find a solution to my problem

我尝试通过放置“;”来解决这个问题,但没有帮助。我还尝试移动 '"playVideo("'+$(this).text() +'")"';到 var 但它也没有帮助。一般来说,我不知道如何解决这个问题请帮我解决这个问题

这是 VS 代码中的样子: 点击这里

javascript html
1个回答
0
投票

我通过正确放置引号来修复它

新代码 JavaScript :

let GettedVideo
const Video_player = document.getElementById('vidplay');

$(window).on('load', function(){
   var fileExt = ".mp4";

        $(document).ready(function(){

            $.ajax({
                //This will retrieve the contents of the folder if the folder is configured as 'browsable'
                url: 'content/videos',
                success: function (data) {
                    console.log(data);
                   $("#fileNames").html('<ul>');
                   //List all xml file names in the page

                    //var filename = this.href.replace(window.location, "").replace("http:///", "");
                   //$("#fileNames").append( '<li>'+filename+'</li>');

                    $(data).find("a:contains(" + fileExt + ")").each(function () {
                       var sa = 'PlayVideo("'+ $(this).text() + '")';
                       console.log(sa)
                        $("#fileNames").append( '<div class="inDiv"<li>'+$(this).text()+ ' '+' </li><button onclick='+ sa +'><i class="fa-solid fa-play"></i> Play</button></div>');
                        GettedVideo = $(this).text()
                        console.log(GettedVideo)
                    });
                    $("#fileNames").append('</ul>');
                }
            });

        });
});

function PlayVideo(targetVideoName) {
   var videoPath = "content/videos/" + targetVideoName;
   console.log(videoPath);
   Video_player.src = videoPath;
   Video_player.load();
   Video_player.play();
   console.log('Video '+ videoPath + ' Playing...');
};
© www.soinside.com 2019 - 2024. All rights reserved.