我想点击链接并让我的JS找出已点击的链接
<ul>
<li><a href="#">Prev</a></li>
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">Next</a></li>
</ul>
所以当点击“1”时,从我的js文件中,我想知道点击了哪个链接..
my.js
events : {
//my click event to call clickedFunction
},
clicked: function(e){ // if 1 is clicked, go to page 1, if 2 is clicked, go to page 2..}
由于
答案 0 :(得分:1)
我会这样做JSBIN
首先在您的UL中添加一个ID,以便我们可以在其他UL中找到它
<ul id="list">
<li><a href="#">Prev</a></li>
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">Next</a></li>
</ul>
然后
var view = Backbone.View.extend({
el : $('#list'), // map the view to your list
initialize: function(){
console.log('started');
},
events : {
"click li" : "clicked" // add an event listener
},
clicked: function(val){ // create a callback to the event
alert("clicked " + val);
}
});
window.app = new view();