HTML의 HTML DOM 메뉴 개체는 를 나타냅니다. 요소.
참고 - <메뉴> Mozilla Firefox 브라우저에서만 지원되는 요소입니다.
구문
다음은 구문입니다 -
<메뉴> 만들기 요소
var menuObject = document.createElement(“MENU”)
예시
HTML DOM 메뉴의 예를 살펴보겠습니다. 요소 -
<!DOCTYPE html>
<html>
<head>
<title>Menu Object</title>
<style>
form {
width:70%;
margin: 0 auto;
text-align: center;
}
* {
padding: 2px;
margin:5px;
}
input[type="button"] {
border-radius: 10px;
}
</style>
</head>
<body>
<form contextmenu="MENU">
<fieldset>
<legend>Menu-Object</legend>
<label for="urlSelect">Current URL:</label>
<input type="url" size="30" id="urlSelect" value="https://www.example.com/aboutUs">
<div id="divDisplay"></div>
</fieldset>
<menu type="context"
id="MENU">
<menuitem label="Get URL"
onclick="contextFunction(1);">
</menuitem>
<menuitem label="Get Hostname"
onclick="contextFunction(2);">
</menuitem>
</menu>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var urlSelect = document.getElementById("urlSelect");
function gethref(){
divDisplay.textContent = 'URL Path: '+location.href;
}
function getHostname(){
divDisplay.textContent = 'Hostname: '+location.hostname;
}
function contextFunction(role){
if(role === 1)
this.gethref();
else
this.getHostname();
}
</script>
</body>
</html> 출력
이것은 다음과 같은 출력을 생성합니다 -
양식을 마우스 오른쪽 버튼으로 클릭 -

'URL 가져오기'를 클릭한 후 컨텍스트 메뉴의 메뉴 항목 -

'호스트 이름 가져오기'를 클릭한 후 컨텍스트 메뉴의 메뉴 항목 -
