single onclick function for buttons with a similar id pattern - JavaScript

前端 未结 4 578
耶瑟儿~
耶瑟儿~ 2021-01-21 03:24

I want to reduce the code.

function one() {
 console.log(\"hai\");
}

document.getElementById(\'dealsButton_1\').onclick = one;
document.getElementById(\'dealsBu         


        
4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-21 03:45

    Here is a solution where you can choose ID name as u wish without a specific pattern of name.

    
      
        
    one
    two

提交回复
热议问题