页面所有的button绑定同一个事件,点击不同的button赋值不同

时间:2022-02-21 09:58:08
 <script type="text/javascript">
$(function(){
$("input[type='button']").click(function(){
var id=$(this).attr("id");
//$.mytest.buttontest(id);
$("#input1").val(id);
})
});
//$.mytest={
//buttontest:function(obj){
//$("#input1").val(obj);
//}
//}
</script>

 <input type="text" value="" id="input1" />
<input type="button" value="button1" id="button1" />
<input type="button" value="button2" id="button2" />
<input type="button" value="button3" id="button3" />
<input type="button" value="button4" id="button4" />
<input type="button" value="button5" id="button5" />

小弟新手~