.contextmenu( handler )
.contextmenu( handler )
설명 : 이벤트 처리기를 "contextmenu"JavaScript 이벤트에 바인딩하거나 요소에서 해당 이벤트를 트리거하십시오.
이 방법은 .on( "contextmenu", handler )첫 번째 두 가지 변형과 .trigger( "contextmenu" )세 번째 변형에 대한 바로 가기입니다 . contextmenu이벤트는 마우스의 오른쪽 버튼이 클릭 된 요소로 전송되지만, 상황에 맞는 메뉴가 표시되기 전에. 컨텍스트 메뉴 키를 누르면 해당 html요소 에서 이벤트가 트리거됩니다 . 모든 HTML 요소는이 이벤트를 수신 할 수 있습니다. 예를 들어, HTML을 고려해보십시오.
<div id="target">
Right-click here
</div>
이벤트 처리기는 <div>다음과 같이 바인딩 될 수 있습니다 .
$( "#target" ).contextmenu(function() {
alert( "Handler for .contextmenu() called." );
});
이 요소를 마우스 오른쪽 버튼으로 클릭하면 경고가 표시됩니다.
.contextmenu ()에 대한 핸들러가 호출되었습니다.
수동으로 이벤트를 트리거하려면 .contextmenu()인수없이 호출하십시오 .
$( "#target" ).contextmenu();
추가 참고 사항 :
애즈 .contextmenu()방법은 단지 속기이고 .on( "contextmenu", handler ), 박리가 사용 가능하다 .off( "contextmenu" ).
예 :
"Hello World!"를 표시하려면 컨텍스트 메뉴 이벤트가 페이지의 단락에서 실행될 때 경고 상자 :
$( "p" ).contextmenu(function() {
alert( "Hello World!" );
});
마우스 오른쪽 버튼을 클릭하여 배경색을 토글합니다.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>contextmenu demo</title>
<style>
div {
background: blue;
color: white;
height: 100px;
width: 150px;
}
div.contextmenu {
background: yellow;
color: black;
}
</style>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<div></div>
<span>Right click the block</span>
<script>
var div = $( "div:first" );
div.contextmenu(function() {
div.toggleClass( "contextmenu" );
});
</script>
</body>
</html>
게시판 목록
개발자팁
질문은 QA에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 4766 | jQuery | 8년 전 | 1679 | ||
| 4765 | jQuery | 8년 전 | 1351 | ||
| 4764 | jQuery | 8년 전 | 2168 | ||
| 4763 | jQuery | 8년 전 | 1856 | ||
| 4762 | jQuery | 8년 전 | 1634 | ||
| 4761 | jQuery | 8년 전 | 1936 | ||
| 4760 | jQuery | 8년 전 | 1301 | ||
| 4759 | jQuery | 8년 전 | 1599 | ||
| 4758 | jQuery | 8년 전 | 1314 | ||
| 4757 | jQuery | 8년 전 | 1280 | ||
| 4756 | jQuery | 8년 전 | 1498 | ||
| 4755 | jQuery | 8년 전 | 1651 | ||
| 4754 | jQuery | 8년 전 | 1616 | ||
| 4753 | jQuery | 8년 전 | 1772 | ||
| 4752 | jQuery | 8년 전 | 1522 | ||
| 4751 | jQuery | 8년 전 | 1842 | ||
| 4750 | jQuery | 8년 전 | 1982 | ||
| 4749 | jQuery | 8년 전 | 1442 | ||
| 4748 | PHP | 8년 전 | 2811 | ||
| 4747 | jQuery | 8년 전 | 1393 | ||
| 4746 | jQuery | 8년 전 | 1650 | ||
| 4745 | jQuery | 8년 전 | 1658 | ||
| 4744 | jQuery | 8년 전 | 1537 | ||
| 4743 | jQuery | 8년 전 | 1614 | ||
| 4742 | jQuery | 8년 전 | 1708 | ||
| 4741 | jQuery | 8년 전 | 1600 | ||
| 4740 | jQuery | 8년 전 | 1610 | ||
| 4739 | jQuery | 8년 전 | 1798 | ||
| 4738 | jQuery | 8년 전 | 1315 | ||
| 4737 | jQuery | 8년 전 | 2101 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기