Document: queryCommandState() ã¡ã½ãã
鿍奍;: ãã®æ©è½ã¯éæ¨å¥¨ã«ãªãã¾ãããã¾ã 対å¿ãã¦ãããã©ã¦ã¶ã¼ãããããããã¾ãããããã§ã«é¢é£ããã¦ã§ãæ¨æºããåé¤ããã¦ããããåé¤ã®æç¶ãä¸ã§ããããäºææ§ã®ããã ãã«æ®ããã¦ããå¯è½æ§ãããã¾ãã使ç¨ãé¿ããã§ããã°æ¢åã®ã³ã¼ãã¯æ´æ°ãã¦ãã ããããã®ãã¼ã¸ã®ä¸é¨ã«ããäºææ§ä¸è¦§è¡¨ãè¦ã¦å¤æãã¦ãã ããããã®æ©è½ã¯çªç¶åä½ããªããªãå¯è½æ§ããããã¨ã«æ³¨æãã¦ãã ããã
鿍æº: ãã®æ©è½ã¯æ¨æºåããã¦ãã¾ããã鿍æºã®æ©è½ã¯ãã©ã¦ã¶ã¼ã®å¯¾å¿ãéãããå°æ¥çã«å¤æ´ã¾ãã¯åé¤ãããå¯è½æ§ããããããæ¬çªç°å¢ã§ã®ä½¿ç¨ã¯æ¨å¥¨ããã¾ããããã ããæ¨æºã®é¸æè¢ãåå¨ããªãç¹å®ã®ã±ã¼ã¹ã§ã¯ãæå¹ãªä»£æ¿ææ®µã¨ãªãå ´åãããã¾ãã
queryCommandState() ã¡ã½ããã¯ãç¾å¨ã®é¸æç¯å²ã«ç¹å®ã® Document.execCommand() ã³ãã³ããé©ç¨ããã¦ãããã©ãããç¥ããã¾ãã
æ§æ
queryCommandState(command)
弿°
command 㯠Document.execCommand() ã®ã³ãã³ãã§ãã
è¿å¤
queryCommandState() ã¯è«çå¤ãã¾ãã¯ç¶æ
ã䏿ãªå ´å㯠null ãè¿ãå¯è½æ§ãããã¾ãã
ä¾
>HTML
<div contenteditable="true">Select a part of this text!</div>
<button onclick="makeBold();">Test the state of the 'bold' command</button>
<hr />
<div id="output"></div>
JavaScript
function makeBold() {
const state = document.queryCommandState("bold");
let message;
switch (state) {
case true:
message = "The bold formatting will be removed from the selected text.";
break;
case false:
message = "The selected text will be displayed in bold.";
break;
default:
message = "The state of the 'bold' command is indeterminable.";
break;
}
document.querySelector("#output").textContent = `Output: ${message}`;
document.execCommand("bold");
}
çµæ
仿§æ¸
ãã®æ©è½ã¯ãç¾å¨ã®ã©ã®ä»æ§ã«ãå«ã¾ãã¦ãã¾ãããæ¨æºåãããäºå®ãããã¾ããã
ãã©ã¦ã¶ã¼ã®äºææ§
é¢é£æ å ±
HTMLElement.contentEditabledocument.designModequeryCommandState()ã«é¢ãããã©ã¦ã¶ã¼ã®ãã°: Scribe's "Browser Inconsistencies" documentation