Jquery - onclick 事件 - 分解
Jquery - onclick event - factorization
我使用 video.js seek option with functions to set time to seek:
$('#0s').click(function(e){
e.preventDefault();
player.currentTime(0);
});
$('#10s').click(function(e){
e.preventDefault();
player.currentTime(10);
});
$('#20s').click(function(e){
e.preventDefault();
player.currentTime(20);
});
});
有了这些 link:
<a href="#" id="0s">0s</a>
<a href="#" id="10s">10s</a>
<a href="#" id="20s">20s</a>
如何只使用一个功能?
我的尝试:
$(".link1").click(function(e){
e.preventDefault();
var time = $('this').attr('time');
player.currentTime(time);
});
有了这个 link:
<a href="#" id="0s" class="link1" time="0">0s</a>
<a href="#" id="10s" class="link1" time="10">10s</a>
<a href="#" id="20s" class="link1" time="20">20s</a>
他们提供这个 url 来测试代码:
http://jsbin.com/ukIDoSa/4/edit?html,js,output
去掉this
两边的引号
var time = $('this').attr('time');
应该是
var time = $(this).attr('time');
player.currentTime(parseInt(time, 10)); // make sure you pass an integer.
使用 var time = $(this).attr('time');不"this"正确的方法只有这个
我使用 video.js seek option with functions to set time to seek:
$('#0s').click(function(e){
e.preventDefault();
player.currentTime(0);
});
$('#10s').click(function(e){
e.preventDefault();
player.currentTime(10);
});
$('#20s').click(function(e){
e.preventDefault();
player.currentTime(20);
});
});
有了这些 link:
<a href="#" id="0s">0s</a>
<a href="#" id="10s">10s</a>
<a href="#" id="20s">20s</a>
如何只使用一个功能? 我的尝试:
$(".link1").click(function(e){
e.preventDefault();
var time = $('this').attr('time');
player.currentTime(time);
});
有了这个 link:
<a href="#" id="0s" class="link1" time="0">0s</a>
<a href="#" id="10s" class="link1" time="10">10s</a>
<a href="#" id="20s" class="link1" time="20">20s</a>
他们提供这个 url 来测试代码: http://jsbin.com/ukIDoSa/4/edit?html,js,output
去掉this
var time = $('this').attr('time');
应该是
var time = $(this).attr('time');
player.currentTime(parseInt(time, 10)); // make sure you pass an integer.
使用 var time = $(this).attr('time');不"this"正确的方法只有这个