如何使用jQuery从列表grop中获取所选值?

如何使用jQuery从列表grop中获取所选值?,jquery,list,twitter-bootstrap-3,Jquery,List,Twitter Bootstrap 3,我需要从列表中的选定值中获取一些值(文本和ID): <div class="list-group col-lg-10" > <a href="#" id="id1" class="list-group-item col-lg-6">Example 1</a> <a href="#" id="id2" class="list-group-item col-lg-6">Example 2</a>

我需要从列表中的选定值中获取一些值(文本和ID):

<div class="list-group col-lg-10" >             
    <a href="#" id="id1" class="list-group-item col-lg-6">Example 1</a>
    <a href="#" id="id2" class="list-group-item col-lg-6">Example 2</a>     
</div>

我只想在点击一个按钮后再拿。我如何获得这些值

    $('a').click(function () {
    var id = $(this).attr('id')
    var text = $(this).html()


    console.log(id)
    console.log(text)
})

$('#get').click(function () {
    var id1 = $('#id1').attr('id')
    var text1 = $('#id1').html()

    var id2 = $('#id2').attr('id')
    var text2 = $('#id2').html()
    console.log(id1)
    console.log(text1)
    console.log(id2)
    console.log(text2)
})
单击创建一个事件,然后在内部使用
$(this).attr('id')
获取id,并使用
$(this).html()获取文本

更新2
StoreValue=[]//声明数组
$(“.list group a”)。单击(函数(){
StoreValue=[];//清除数组
StoreValue.push($(this.attr(“id”));//将id添加到数组
StoreValue.push($(this.text());//向数组添加文本
})
$(“.button”)。单击(函数(){
警报(StoreValue[0]+“”+StoreValue[1])
})


单击此处
我不需要所有列表值,只需要我选择的值。单击只需在按钮上起作用。我考虑过这个方法:将值存储在click-on标记之后,然后在click-on按钮之后使用它。