我被 html/JS 困住了,不知道我应该如何处理一些事件。例如我有一个列表组:
<div class="col-lg-3 col-md-3 col-sm-3 opciones">
<div class="list-group">
<a href="#" class="list-group-item active">
Tokyo
</a> // barfoobarfoo
<a href="#" class="list-group-item">London</a> // foo
<a href="#" class="list-group-item">Paris</a> // bar
<a href="#" class="list-group-item">Moscow</a> // foobar
<a href="#" class="list-group-item">NY</a> //foobarfoo
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我想做的是:
1)单击时更改活动元素。
2)点击元素时调用JS函数。UPD:所以现在我知道可以使用 JQuery 处理单击事件。
我不明白的是如何确定点击了哪个元素。例如 JQuery:
$('.list-group-item').on('click', function() {
$this = $(this);
$('.active').removeClass('active');
$this.toggleClass('active')
function simpleFunc(someargument) { //value of this argument depends on clicked item and can be (foo|bar|foobar ) etc
document.write(someargument) // here whould be written some text (foo|bar|foobar …Run Code Online (Sandbox Code Playgroud)