gpt4 book ai didi

javascript - 使用 jquery 播放暂停嵌入式 vlc 播放器

转载 作者:行者123 更新时间:2023-11-30 18:27:44 24 4
gpt4 key购买 nike

我在 html 中嵌入了 vlcplayer 并想播放、暂停视频。所以我创建了一个 javascript 文件并编写了一些函数

<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>

javascript文件有

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

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

当我点击播放链接时,警告框没有出现。是我给 onclick 值的方式有误吗?

最佳答案

您的函数 playpause 被定义为您提供给 ready 函数的函数的局部变量。所以它们对 DOM 对象不可见。

一个解决方案可能是以通常的方式声明它们(或 window.play = function...)。

但是使用 jquery 的正确方法是使用 jquery 绑定(bind)函数:

    <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");
}
});
}
);

关于javascript - 使用 jquery 播放暂停嵌入式 vlc 播放器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10413957/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com