0

如何同时执行 2 个功能。在下面带有 onclick 的代码片段中,我获取了id父 Div 的 ,然后使用id

<div id="selDe">
<input type="radio" class="ger" id="num1" checked><label for="num1">
<input type="radio" class="ger" id="num2"><label for="num2">
</div>
<div id="selRe" >
<input type="radio" class="ger" id="num1" checked><label for="num1">
<input type="radio" class="ger" id="num2"><label for="num2">

JS:

<script>
$(".ger").on({
    click:function(){
        var pid = $(this).parent().attr("id");  //get the name of the div parent
        $("#"+pid+" .ger").on({   
//execute the function, but it just works after the next click
            click: function () {
                var showV = this.id.slice(3);
                alert(showV)
            }
        });
    }
});

4

1 回答 1

1

试试这个:

$('div[id^=sel]').on('click', '.ger, div[id^=sel] .ger', function () {
    var pid = $(this).parent().attr("id");
    alert(pid);
    var showV = this.id.slice(3);
    alert(showV);
});
于 2013-05-01T17:25:04.987 回答