0
如何在同一時間執行2個功能。在下面的onclick的代碼片段,我得到父Div的id
,然後使用id
執行功能,在一個點擊處理程序中執行2個功能
<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)
}
});
}
});
我不認爲這是可能的在JS – Adrift 2013-05-01 17:17:56
ID應該始終是獨一無二的....這就是爲什麼它被稱爲「ID」 – bipen 2013-05-01 17:19:13
我認爲你的意思是「在一個點擊處理程序」,而不是「在同一時間」。這是完全可能的。 – 2013-05-01 17:19:42