0

在播放视频时,我有 2 行文本,第一行是新文本,第二行是从第一行向上移动的旧文本。但是,在 for 循环期间,第二行甚至根本不替换,因为两行显示相同的文本。任何人都可以告诉我它有什么问题吗?“text”是第一行,“second”是第二行。请帮忙。这里我的 javascript 代码和网站是 [a link] http://www.cs.rit.edu/~rskics/study/caption2/test.html(在 firefox 上工作),

var subtitleArray = new Array(); //stored all values from XML caption file

var tempText = "";  

    $(document).ready(function(){
                            //alert("get caption 1");
                            getCaption();

                            var subtitle2 = document.getElementById('subtitle2');

                            var video = document.getElementById('video');



                            $("#video").bind('timeupdate',function(){


                                var text = "", cap = "";

                                    for( var i = 0; i < subtitleArray.length;i++)
                                    {

                                        var cueStart = parseFloat(subtitleArray[i][0]);
                                        var cueEnd = cueStart + parseFloat(subtitleArray[i][1]);

                                        cap = subtitleArray[i][2];

                                        if (video.currentTime >= cueStart && video.currentTime <= cueEnd) {
                                           text = cap;   
                                        }


                                        if ( text != tempText && text != "" ) {
                                        console.log( text );
                                        console.log(tempText);
                                            $("#second").html(text);
                                        }

                                        subtitle2.innerHTML = text;
                                        tempText = text;
                                        console.log( tempText );

                                    }
                            });
                        });
4

1 回答 1

0

我找到了解决方案,这里有一个代码

var tempText = "", prevText="";

$("#video").bind('timeupdate',function(){


                        var text = "", cap = "";

                            for( var i = 0; i < subtitleArray.length;i++)
                            {

                                var cueStart = parseFloat(subtitleArray[i][0]);
                                var cueEnd = cueStart + parseFloat(subtitleArray[i][1]);

                                cap = subtitleArray[i][2];

                                if (video.currentTime >= cueStart && video.currentTime <= cueEnd) {
                                   text = cap;   
                                }

                                if (tempText != text && text != "") {

                                    prevText = tempText;
                                    $("#second").html(prevText);
                                }

                                subtitle.innerHTML = text;

                                if ( text != "" ) {
                                    tempText = text;
                                }


                            }
                    });
于 2013-04-04T21:04:34.893 回答