我有4个不同身份的按钮.当我点击它们时,我需要执行一个功能.所以我需要这样的东西:
$('#button #button').click(function()
解决方法
要一次选择4个按钮,请编写以下内容:
$('#button1,#button2,#button3,#button4').click(function(event){ /* code here */ });
如果您需要确定按下了哪个按钮,请写下以下内容:
$('#button1,#button4').click(function(event){
if($(event.target).attr('id')=='button1'){
/* specific code for button1 */
} else if($(event.target).attr('id')=='button2'){
/* specific code for button2 */
} else if($(event.target).attr('id')=='button3'){
/* specific code for button3 */
} else if($(event.target).attr('id')=='button4'){
/* specific code for button4 */
}
});