补充代码,鼠标单击Button1后将Button1移动到Button2的后面

前端面试笔试题分类: JavaScript编码补充代码,鼠标单击Button1后将Button1移动到Button2的后面
0
前端学堂 管理员 asked 10月 ago
笑语 管理员 replied 5月 ago

补充代码,鼠标单击Button1后将Button1移动到Button2的后面

1 Answers
0
前端学堂 管理员 answered 10月 ago
var btn1 = document.getElementById('button1');
var btn2 = document.getElementById('button2');

addListener(btn1, ‘click’, function (event) {
btn1.parentNode.insertBefore(btn2, btn1);
});

function addListener(elem, type, handler) {
if (elem.addEventListener) {
elem.addEventListener(type, handler, false);
return handler;
} else if (elem.attachEvent) {
function wrapper() {
var event = window.event;
event.target = event.srcElement;
handler.call(elem, event);
}
elem.attachEvent(‘on’ + type, wrapper);
return wrapper;
}
}

Your Answer

如果对您有帮助,别忘了打赏一下宝宝哦!

支付宝扫一扫打赏

微信扫一扫打赏