2 qq 21741673 qq_21741673 于 2016.02.25 15:34 提问

jquery获取相同class的div并绑定点击事件
<div id="outadded_content">
            <div class="outadded_menu">
                <img style="height:65%;width:80%;" src="../image/more.png" />
                <span>菜单1</span>
            </div>
            <div class="outadded_menu">
                <img style="height:65%;width:80%;" src="../image/more.png" />
                <span>菜单2</span>
            </div>
            <div class="outadded_menu">
                <img style="height:65%;width:80%;" src="../image/more.png" />
                <div>菜单3</div>
            </div>
            <div class="outadded_menu">
                <img style="height:65%;width:80%;" src="../image/more.png" />
                <span>菜单4</span>
            </div>
            <div class="outadded_menu" id="a">
                <img style="height:65%;width:80%;" src="../image/more.png" />
                <span>菜单5</span>
            </div>
        </div>

需要用jquery获取class为outadded_menu的div对象,并且绑定点击事件,获取所点击的div的id的值。

在线等...

8个回答

qq_19891827
qq_19891827   2016.02.25 15:57
 $('.outadded_menu').click(function(){
     console.log($(this).attr('id'));
 })
wufeiya
wufeiya   2016.02.25 16:21

$('.outadded_menu').each(function(){
$(this).click(function){
alert($(this).html())
}
})

cherry91xw
cherry91xw   2016.02.25 15:40

$(".outadded_menu").fclick(function () {
var clickId = this.id;
});

cherry91xw
cherry91xw   2016.02.25 15:40

fclick换成click事件,手误

u012682006
u012682006   2016.02.25 16:05
var ArrayMenu = $('.outadded_menu');
    for(var i = 0;i < ArrayMenu.length; i++){   
        //绑定方法每个菜单的点击
        $(ArrayMenu[i]).bind("click",{'bindText':i},function ChangContent(e){
            var num = e.data.bindText;
            alert(num+"你的事件");
        });
    }
a1073727231
a1073727231   2016.02.25 16:07
$('.outadded_menu').click(function(){event.....});
当有顺序之分的时候,我是用blind("click",function(){event.....});

lizhao861018
lizhao861018   2016.02.25 16:17

$('.outadded_menu').on('click',function(){
alert($(this).attr('id'));
});

lkycn
lkycn   2016.02.26 10:23

$('.outadded_menu').on("click",function(){
if($(this).attr('id')){
console.log($(this).attr('id'));
}
})
如何学习js

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!