W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <p>Click this button to invoke an onclick event, and check whether it is trusted:</p> <button id="myBtn" onclick="myFunction(event)">试一试</button> <p>Click this button to trigger an onclick event by a script, and check whether it is trusted:</p> <button onclick="triggerClick()">试一试</button> <p><b>注释:</b> The isTrusted property is not supported in Safari and IE8 and earlier.</p> <script> function myFunction(event) { if ("isTrusted" in event) { if (event.isTrusted) { alert ("The " + event.type + " event is trusted."); } else { alert ("The " + event.type + " event is not trusted."); } } else { alert ("The isTrusted property is not supported by your browser"); } } function triggerClick() { var btn = document.getElementById("myBtn"); btn.click(); } </script> </body> </html>