Single event handler for four button clicks

被刻印的时光 ゝ 提交于 2019-12-02 13:42:47

Since you are using jquery, you don't need the onclick attribute, just add a class that is similar for all buttons. And DO NOT forget to add the js file of jquery above all js files

$('.someClass').click(function() {
  alert($(this).val());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input class="someClass" type="button" value="one"><br>
<input class="someClass" type="button" value="two"><br>
<input class="someClass" type="button" value="three"><br>
<input class="someClass" type="button" value="four"><br>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!