给input 加了个click事件
$(document).ready(function() { $("input[@type='button']").click(function() {  alert("2");});});
在页面有
<input type="button" value=" 添加 "  onclick="alert("1");" />  
这样的话 我点添加按钮时,是先alert("1")然后alert("2"),有没有办法先alert("2")再alert("1"),
谢谢各位了。

解决方案 »

  1.   


    <script src="js/jquery-1.3.2.js" type="text/javascript"> </script> 
    <script>
    window.onload=function(){
    $(document).ready(function(){
    var fn = $("input[type='button']")[0].onclick;
    $("input[type='button']")[0].onclick = null;
    $("input[type='button']").click(function() { alert("2"); fn();});
    }); }
    </script><input type="button" value=" 添加 "  onclick="alert('1');" /> 
      

  2.   

    多谢楼上的,再问下如果有2个button
    <input type="button" value=" 添加1 "  onclick="alert('1');" /> 
    <input type="button" value=" 添加2 "  onclick="alert('3');" /> 
    并且点 "添加1"按钮时 弹出顺序是alert('2'),alert('1')
    点 "添加2" 按钮时 弹出顺序是alert('3'),alert('1')
    需要怎么实现,多谢了!!
      

  3.   

    不好意思上面写错了
    多谢楼上的,再问下如果有2个button 
    <input type="button" value=" 添加1 "  onclick="alert('1');" /> 
    <input type="button" value=" 添加2 "  onclick="alert('3');" /> 
    并且点 "添加1"按钮时 弹出顺序是alert('2'),alert('1') 
    点 "添加2" 按钮时 弹出顺序是alert('2'),alert('3') 
    需要怎么实现,多谢了!! 
      

  4.   


    <script>
    window.onload=function(){
    $(document).ready(function(){
    var afn = [];
    var newfun = [];
    newfun[0] = function(){alert("2");};
    newfun[1] = function(){alert("3");}; $("input[type='button']").each(function(i){
    afn[i] = $(this)[0].onclick;
    $(this)[0].onclick = null;
    $(this).bind("click",newfun[i]).bind("click",afn[i]);
    })
    }); }
    </script><input type="button" value=" 添加1 "  onclick="alert('11');" /> 
    <input type="button" value=" 添加2 "  onclick="alert('12');" />