1

I embedded vlcplayer in html and wanted to play ,pause the video .So I created a javascript file and coded some functions

<head>
<script type="text/javascript"  src="jquery-1.7.1.min.js" ></script>
<script type="text/javascript"  src="vctrl.js" ></script>
</head>
<body>
<embed id="vlcp" type="application/x-vlc-plugin" name="VLC"  autoplay="no" loop="no" volume="100" width="640" height="480" target="test.flv">
</embed>
<a href="#" onclick='play()'>Play</a>
<a href="#" onclick='pause()'>Pause</a>
</body>

The javascript file has

$(document).ready(function(){
    var player = document.getElementById("vlcp");
    var play = function(){
        if(player){
            alert("play");
        }
    };

    var pause = function(){
        if(player){
            alert("pause");
        }
    };        
}
);

When I click on the play link ,the alert box doesn't appear..Is the way I have given the onclick value wrong?

4

2 回答 2

2

Your functions play and pause are defined as local variable of the function you give to the ready function. So they're not visible to the DOM objects.

A solution could be to declare them in an usual way (or window.play = function...).

But the correct way using jquery is to use jquery binding functions :

    <head>
    <script type="text/javascript"  src="jquery-1.7.1.min.js" ></script>
    <script type="text/javascript"  src="vctrl.js" ></script>
    </head>
    <body>
    <embed id="vlcp" type="application/x-vlc-plugin" name="VLC"  autoplay="no" loop="no" volume="100" width="640" height="480" target="test.flv">
    </embed>
    <a id=playbutton href="#">Play</a>
    <a id=pausebutton href="#">Pause</a>
    </body>



    $(document).ready(function(){
        var player = document.getElementById("vlcp");
        $('#playbutton').click(function(){
            if(player){
                alert("play");
            }
        });

        $('#pausebutton').click(function(){
            if(player){
                alert("pause");
            }
        });        
    }
    );  
于 2012-05-02T13:02:39.987 回答
0
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript"  src="vctrl.js" ></script>
</head>
<body>
<embed id="vlcp" type="application/x-vlc-plugin" name="VLC"  autoplay="no" loop="no" volume="100" width="640" height="480" target="test.flv">
</embed>
<a href="javascript:void(0);" class="play" onclick='play()'>Play</a>
<a href="javascript:void(0);" class="play" onclick='pause()'>Pause</a>
</body>


<script type="text/javascript">
$(document).ready(function(){
var player = document.getElementById("vlcp");
$('.play').click(function(){
var thisvalue = $(this).html();
if(thisvalue=="Play"){
alert("Play");
}else{
if(thisvalue=="Pause"){
alert("Pause");
}
}
});
});
</script>
于 2012-05-02T13:02:48.617 回答