html部分
<input type="button" name="chk2" id="chk2" value="3"
onclick="document.write('mothedX->')/>JS部分function mothedB(){document.write("mothedB->")};
function mothedC(){document.write("mothedC->")};
chk2.attachEvent('onclick',mothedB);
chk2.attachEvent('onclick',mothedC);执行顺序是 mothedX->mothedB-> mothedC 但是我想要mothedB-> mothedC ->mothedX的效果,因为在我的程序中mothedX是用来打印处理mothedB,mothedC以后值的,现在的结果总是打印执行之前的值,是不对的.前提,我希望onclick="document.write('mothedX->')部分不变 ,不希望再去chk2.attachEvent('onclick',mothedX);之类的,原因上面的button我已经封装到控件中动态生成去了
<input type="button" name="chk2" id="chk2" value="3"
onclick="document.write('mothedX->')/>JS部分function mothedB(){document.write("mothedB->")};
function mothedC(){document.write("mothedC->")};
chk2.attachEvent('onclick',mothedB);
chk2.attachEvent('onclick',mothedC);执行顺序是 mothedX->mothedB-> mothedC 但是我想要mothedB-> mothedC ->mothedX的效果,因为在我的程序中mothedX是用来打印处理mothedB,mothedC以后值的,现在的结果总是打印执行之前的值,是不对的.前提,我希望onclick="document.write('mothedX->')部分不变 ,不希望再去chk2.attachEvent('onclick',mothedX);之类的,原因上面的button我已经封装到控件中动态生成去了
var methedX = chk2.onclick;//先将现有事件绑定的方法储存
chk2.onclick = methedB;//替换现有事件绑定方法为B
chk2.attachEvent('onclick',mothedC);//追加C
chk2.attachEvent('onclick',mothedX);//追加X
//你上面写错了,是先追加的后运行;so B-X-C