[英]Applying a function to all buttons?
Im working on a quick script to apply an alert and redirect message to all anchors and buttons on a page. 我正在制作一个快速脚本,以将警报和重定向消息应用于页面上的所有锚点和按钮。 So far, I have this working for all anchors:
到目前为止,我已经为所有锚点工作了:
document.querySelector('body')
.addEventListener('click', function (event) {
if
(event.target.tagName === 'A' || event.target.tagName === 'button') {
event.preventDefault();
alert("test");
window.open('http://www.test.com', '_self');
}
});
When i try to apply the same idea to all buttons (see after the || in the script), it does not apply. 当我尝试将相同的想法应用于所有按钮时(请参见脚本中的||之后),该方法不适用。 Am I missing something?
我想念什么吗?
event.target.tagName
results are capitalized. event.target.tagName
结果大写。
A
BUTTON
TEXTAREA
etc. A
BUTTON
TEXTAREA
等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.