我正在使用 jQuery 开发 HTML5 视频播放器。现在我的视频播放器工作得很好,但我想获取视频持续时间的变量并在纯 HTML 页面中显示/显示它。
因此,从这里您可以获取有关此 Jquery 视频播放器的更多信息: http://www.videojs.com/docs/api/
我认为视频持续时间的变量是:myPlayer.duration();
如何在 HTML 中显示该值?
这是我用来显示播放器的 HTML 代码:
<video id="vemvo-player" class="video-js vjs-default-skin" controls autoplay="true" width="950" height="534"
data-setup="{}">
<source src="[var.base_url]/uploads/[var.video_play]" type='video/flv' />
</video>
Run Code Online (Sandbox Code Playgroud)
这就是我试图显示这个变量的内容,但它说它=“0”,而在视频播放器上它说它是4分钟:
<video id="vemvo-player" class="video-js vjs-default-skin" controls autoplay="true" width="950" height="534"
data-setup="{}">
<source src="[var.base_url]/uploads/[var.video_play]" type='video/flv' />
</video>
<div id="duration"></div>
<script type="text/javascript">
_V_("vemvo-player").ready(function(){
var myPlayer = this;
var howLongIsThis = myPlayer.duration();
$('#duration').html('Duration: ' + howLongIsThis);
});
</script>
Run Code Online (Sandbox Code Playgroud)
我的错误在哪里?
我正在使用这个JavaScript:
$.getJSON("/aTest.json", function (jsonObj) {
$("#testJSONBtn").click(function () {
var val = "";
for (var i = 0; i <= jsonObj.events.length; ++i) {
val += jsonObj.events[i].title + ", " + jsonObj.events[i].date + ", " + jsonObj.events[i].explanation + "<br/>";
}
$("#JSONOutput").append(val);
});
});
Run Code Online (Sandbox Code Playgroud)
要访问json文件:
{
"events":
[
{"title":"Okmulgee Public Schools Starts 3rd Quarter" , "date":"1-2-2013" , "explanation":"Okmulgee Public Schools begins its third quarter."},
{"title":"Okmulgee Public Schools-Closed in Observance of Martin Luther King Jr. Holiday" , "date":"1-21-2013" , "explanation":"The Okmulgee Public Schools will …Run Code Online (Sandbox Code Playgroud) 假设我有一个带有id的按钮:
<input id='someButton' />
我想在这个按钮上附加一个事件监听器:
$('#form').on('click', '#someButton', function() {
alert("My listener called");
Run Code Online (Sandbox Code Playgroud)
});
但是,在我不知情的情况下,之前有人为这个相同的按钮编写了一个事件监听器:
$('#form').on('click', '#someButton', function() {
alert("Some other listener called");
});
Run Code Online (Sandbox Code Playgroud)
我遇到了一些有效地执行上述操作的代码,看起来第一个注册的侦听器就是使用的那个.我是否正确假设jQuery将始终调用在特定id(并且只有该侦听器)上注册的第一个事件侦听器?
我想禁用我的类中未选中复选框的所有元素.但即使这被检查,我的if返回false.
$('.myClass').each(function(i, obj) {
if (!$j('input[name='+obj.id+']').is(':checked')){
$j('#desc_'+obj.id).attr('disabled','disabled');
}
});
Run Code Online (Sandbox Code Playgroud)
但是,如果我在if内部发出警报,它的作品!
$('.myClass').each(function(i, obj) {
if (!$j('input[name='+obj.id+']').is(':checked')){
alert($j('input[name='+obj.id+']').is(':checked'));
$j('#desc_'+obj.id).attr('disabled','disabled');
}
});
Run Code Online (Sandbox Code Playgroud)
谁知道为什么?
在 javascript 中什么情况下会使用console.logand return?
我刚刚开始学习 javascript,我想知道我会在哪些情况下使用它们?