HTMLButtonElement: command-Eigenschaft
Experimentell: Dies ist eine experimentelle Technologie
Überprüfen Sie die Browser-Kompatibilitätstabelle sorgfältig vor der Verwendung auf produktiven Webseiten.
Die command
-Eigenschaft der HTMLButtonElement
-Schnittstelle ruft die Aktion ab und legt sie fest, die auf einem Element ausgeführt werden soll, das von dieser Schaltfläche gesteuert wird. Damit dies Wirkung zeigt, muss commandfor
gesetzt sein.
Sie spiegelt das command
-HTML-Attribut wider.
Wert
Ein String. Siehe das command
-Attribut für gültige Werte.
Beispiele
Einfaches Beispiel
<button id="toggleBtn" commandfor="mypopover" command="toggle-popover">
Toggle popover
</button>
<div popover id="mypopover">
<button commandfor="mypopover" command="hide-popover">Hide popover</button>
</div>
const popover = document.getElementById("mypopover");
const toggleBtn = document.getElementById("toggleBtn");
toggleBtn.command = "show-popover";
Benutzerdefiniertes Beispiel mit Events
<button commandfor="the-image" command="--rotate-left">Rotate Left</button>
<button commandfor="the-image" command="--rotate-right">Rotate Right</button>
<img id="the-image" src="photo.jpg" alt="[add appropriate alt text here]" />
const image = document.getElementById("the-image");
image.addEventListener("command", (event) => {
if (event.command == "--rotate-left") {
event.target.style.rotate = "-90deg";
} else if (event.command == "--rotate-right") {
event.target.style.rotate = "90deg";
}
});
Spezifikationen
Specification |
---|
HTML # dom-button-command |
Browser-Kompatibilität
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
command |
Legend
Tip: you can click/tap on a cell for more information.
- No support
- No support
- Experimental. Expect behavior to change in the future.
- User must explicitly enable this feature.