页面所有的button绑定同一个事件,点击不同的button赋值不同
1 <script type="text/javascript"> 2 $(function(){ 3 $("input[type='button']").click(function(){ 4 var id=$(this).attr("id"); 5 //$.mytest.buttontest(id); 6 $("#input1").val(id); 7 }) 8 }); 9 //$.mytest={ 10 //buttontest:function(obj){ 11 //$("#input1").val(obj); 12 //} 13 //} 14 </script>
1 <input type="text" value="" id="input1" /> 2 <input type="button" value="button1" id="button1" /> 3 <input type="button" value="button2" id="button2" /> 4 <input type="button" value="button3" id="button3" /> 5 <input type="button" value="button4" id="button4" /> 6 <input type="button" value="button5" id="button5" />
小弟新手~