我可以将 JavaScript 事件包装在 jQuery 事件中吗?
jqueryweb developmentfront end technology更新于 2026/1/15 21:37:17
可以,您可以将 JavaScript 事件包装在 jQuery 事件中。包装时,请使用事件对象。您可以尝试运行以下代码,将 JavaScript 事件包装在 jQuery 事件中 −
示例
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('a.one').click(function(event){
event.preventDefault();
});
function test(event){
$.Event(event).preventDefault();
}
});
</script>
<style type="text/css">
a.test {
font-weight: bold;
}
body {
font-family:sans-serif;
}
</style>
</head>
<body>
<a class="one" href="https://tutorialspoint.com/">Tutorials</a><br/>
<a class="two" href="https://qries.com/" onclick='test(event)'>QA</a>
</body>
</html>

