วิธี HTML DOM Document execCommand()

คำนิยามและวิธีใช้

execCommand() มีการยกเลิกคำสั่ง โปรดไม่ใช้มัน

คุณสมบัติ applet จะส่งกลับค่าว่างในทุกเว็บเครื่องคอมพิวเตอร์ใหม่ HTMLCollection.

HTML5 ไม่สนับสนุนองค์ประกอบ <applet> แล้ว

ทางเลือก

คุณสมบัติ designMode ของ Document

คุณสมบัติ contentEditable ของ Element

ตัวอย่าง

ทำให้ข้อความที่เลือกเป็นแบบหนา

document.execCommand("bold");

ลองทดลองด้วยตัวเอง

รูปแบบ

document.execCommand(command, showUI, value)

ตัวแปร

ตัวแปร รายละเอียด
command

ชื่อคำสั่งที่ต้องทำงาน

  • "backColor"
  • "bold"
  • "createLink"
  • "copy"
  • "cut"
  • "defaultParagraphSeparator"
  • "delete"
  • "fontName"
  • "fontSize"
  • "foreColor"
  • "formatBlock"
  • "forwardDelete"
  • "insertHorizontalRule"
  • "insertHTML"
  • "insertImage"
  • "insertLineBreak"
  • "insertOrderedList"
  • "insertParagraph"
  • "insertText"
  • "insertUnorderedList"
  • "justifyCenter"
  • "justifyFull"
  • "justifyLeft"
  • "justifyRight"
  • "outdent"
  • "paste"
  • "redo"
  • "selectAll"
  • "strikethrough"
  • "styleWithCss"
  • "subscript"
  • "superscript"
  • "undo"
  • "unlink"
  • "useCSS"
showUI ค่าบูล กำหนดว่าควรแสดง UI หรือไม่
value บางคำสั่งต้องมีค่าเพื่อที่จะสามารถทำงานได้

ค่าที่ส่งกลับ

ประเภท รายละเอียด
ค่าบูล ถ้าสนับสนุนคำสั่งนี้ จะเป็น true ไม่เช่นนั้นจะเป็น false。