JavaScript中怎么写自定义类和事件
1个回答
展开全部
js自定义类不太清楚,自定义事件 baidu下 js中的 CustomEvent 就可以,如下:
myElement.addEventListener("userLogin", function(e) {
console.info("Event is: ", e);
console.info("Custom data is: ", e.detail);
})
// First create the eventvar myEvent = new CustomEvent("userLogin", {
detail: {
username: "davidwalsh"
}
});// Trigger it!
myElement.dispatchEvent(myEvent);
myElement.addEventListener("userLogin", function(e) {
console.info("Event is: ", e);
console.info("Custom data is: ", e.detail);
})
// First create the eventvar myEvent = new CustomEvent("userLogin", {
detail: {
username: "davidwalsh"
}
});// Trigger it!
myElement.dispatchEvent(myEvent);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询