이를 위해 JavaScript에서 preventDefault()를 사용하십시오. 다음은 자바스크립트 코드입니다 -
예시
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>
<a href="urlLink">Press Me to see logs</a>
<a href="urlLink">Press Me to see logs in console</a>
<a href="#">Nothing will happen</a>
<script>
$(function(){
$("a:not([href='#'])").click(function(event){
event.preventDefault();
console.log("You have pressed me!!!!!");
});
});
</script>
</body>
</html> 위의 프로그램을 실행하려면 파일 이름을 anyName.html(index.html)로 저장하세요. 파일을 마우스 오른쪽 버튼으로 클릭합니다. 라이브 서버로 열기 옵션을 선택합니다. 대에서 코드 편집기.
출력

두 링크를 클릭하면 Press Me 로그를 보고 Press Me 콘솔에서 로그를 보려면 콘솔 출력을 얻을 수 있습니다. 그러나 링크를 클릭하면 아무 일도 일어나지 않습니다 , 그러면 아무 것도 인쇄되지 않습니다 -

위에서 Press Me를 눌렀습니다. 출력을 표시하기 위해 로그를 봅니다.
링크를 클릭하면 아무 일도 일어나지 않습니다 , 그러면 아래 출력과 같이 아무 것도 인쇄하지 않습니다 -
