javascript代码分别写入html标记

时间:2014-07-06 11:51:52

标签: javascript

这段代码出了什么问题,我已经包含了文件,但是当我运行它并没有给出我想要的结果(视频播放器的自定义设计)时,任何了解javascript的人都可以帮助......

function dofirst() {

    //get values of buttons
    var movie = document.getElementById("movie");
    var playOrpause = document.getElementById("playOrpause");
    var mute = document.getElementById("mute");
    var fullscreen = document.getElementById("fullscreen");

    //get values of sliders
    var seekbar = document.getElementById("seekbar");
    var myvolume = document.getElementById("volume");


    //add the event listeners to buttons

    playOrpause.addEventListener('click', playme, false);
    mute.addEventListener('click', mute_me, false);
    fullscreen.addEventListener('click', scree_full, false);

    //add the event listener to sliders 
    seekbar.addEventListener('change', change_me, false);
    seekbar.addEventListener('timeupdate', update_me, false);
    seekbar.addEventListener('mousedown', mous_down, false);
    seekbar.addEventListener('mouseup', mous_up, false);
    myvolume.addEventListener('change', volume_up, false);

}

//the functions of play button



function playme() {
    if (movie.paused == true) {
        movie.play();
        //update button status
        playOrpause.innerHTML = 'pause';
        else {
            movie.pause();
            //update button status
            playOrpause.innerHTML = 'play';
        }
    }
}

//the functions of mute button



function mute_me() {
    if (movie.muted == false) {
        movie.muted = true;
        //update button status
        mute.innerHTML = 'unmute';
    } else {
        movie.muted = false;
        //update button status
        mute.innerHTML = 'mute';
    }



}

//the functions of fullscreen button


function scree_full() {
    if (movie.requestFullscreen) {
        movie.requestFullscreen();
    }
    //for mozilla  firefox browser
    else if (movie.mozRequestFullscreen) {

        movie.mozRequestFullscreen();
    }
    //for google chrome browsers
    else if (movie.webkitRequestFullscreen) {
        movie.webkitRequestFullscreen();
    }
}

//the functions for seekbar 

function change_me() {
    //calculate current time of the video
    var time = movie.duration * (seekbar.value / 100);
    //update the current time of the video
    movie.currentTime = time;
}

//update the seekbar when the video plays

function update_me() {
    var size = movie.currentTime * (100 / movie.duration);

    //update the size of the seekbar
    seekbar.value = size;

}

//pause the video when the seekbar is dragged


function mous_down() {
    movie.pause();
}

//play the video when the seekbar is dropped

function mous_up() {
    movie.play();
}

//the function for the volume bar

function volume_up() {
    movie.volume = myvolume.value;
}
window.addEventListener("load", dofirst, false);

1 个答案:

答案 0 :(得分:0)

确保代码中没有语法错误....例如,您似乎正在使用' mous_up()'而不是' mouse_up()'。根据我自己的经验,当有任何语法错误时,javascript代码不会运行。