EN
이 콘텐츠는 한국어로 제공되지 않아 영어 버전으로 표시됩니다.

contenteditable attribute | contentEditable property

Sets or retrieves the string that indicates whether the user can edit the content of the object.

Syntax

HTML<element contenteditable="p" ... >
JavaScript

p = object.contentEditable

Property values

Type: String

inherit

Default. Content's ability to be edited by user is inherited from object's parent.

false

Content cannot be edited by the user.

true

Content can be edited by the user.

Remarks

Child elements do not inherit this attribute unless they have layout. Use the hasLayout property to determine if an object has layout.

If this attribute is applied to a body element, it has the same effect as setting the designMode property of the document object.

Elements with the disabled attribute set to false do not respond to the contentEditable attribute.

If this attribute is applied to the A element, the default functionality of the A element will be lost while p is set to the value of true.

If this attribute is applied to the marquee element, the default functionality of the marquee element will be lost while p is set to the value of true.

Though the TABLE, COL, COLGROUP, TBODY, TD, TFOOT, TH, THEAD, and TR elements cannot be set as content editable directly, a content editable SPAN, or DIV element can be placed inside the individual table cells (TD and TH elements). See the example below.

Security Warning:  Users can change the contents of a document when the contentEditable property is set to TRUE. Using this property incorrectly can compromise the security of your application. Incorrect use of the contentEditable property might include not validating user input. If you do not validate user input, a malicious user can inject control characters or script that can harm your data. You should take routine precautions against displaying unvalidated user input. For more information, see Security Considerations: Dynamic HTML.

Windows Internet Explorer 8 and later. When a webpage is displayed in IE8 Standards mode, an object cannot receive focus when p is set to false. When pages are displayed in earlier document compatibility modes, objects can receive focus when p is false.

Examples

In the following example, setting the DIV elements to have 100% height and width makes all content within the borders of the cells editable.


<p>Table 1 Editable</p><br/>
<table border="1" width="80%">
<thead>
<tr>
<th><div contenteditable style="height: "100%"; width: "100%";">Heading 1 <div></th>
<th><div contenteditable style="height: "100%"; width: "100%";">Heading 2 <div></th>
</tr>
</thead>
<tbody>
<tr>
<td><div contenteditable style="height: "100%"; width: "100%";">Row 1, Column 1 text.<div></td>
<td><div contenteditable style="height: "100%"; width: "100%";">Row 1, Column 2 text.<div></td>
</tr>
<tr>
<td><div contenteditable style="height: "100%"; width: "100%";">Row 2, Column 1 text.<div></td>
<td><div contenteditable style="height: "100%"; width: "100%";">Row 2, Column 2 text.<div></td>
</tr>
</tbody>
</table>



The following example shows how to use the contentEditable property to control whether the user can edit the content of the object.

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/contentEditableEX2.htm


<head>
<script type="text/javascript">
  function chgSpan() {
    currentState = oSpan.isContentEditable;
    newState = !currentState;
    oSpan.contentEditable = newState;
    oCurrentValue.innerText = newState;
    newState == false ? oBtn.innerText = "Enable Editing" :
        oBtn.innerText = "Disable Editing"
  }
</script>
</head>
<body onload="oCurrentValue.innerText = oSpan.isContentEditable;">
<p>Click the button to enable or disable span content editing.</p>
<p>
<button id="oBtn" onclick="chgSpan()">Enable Editing</button>
</p>
<p><span id="oSpan">You can edit this text.</span></p>
SPAN can be edited: <span id="oCurrentValue"></span>
</body>



This example demonstrates the features of Internet Explorer that enable users to edit the content of an HTML element directly from the browser.

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/editRegions.htm

See also

a
abbr
acronym
address
b
bdo
big
blockQuote
body
button
center
cite
code
custom
dd
defaults
del
dfn
dir
div
dl
dt
em
fieldSet
font
form
hn
i
input type=button
input type=email
input type=number
input type=password
input type=radio
input type=range
input type=reset
input type=search
input type=submit
input type=tel
input type=text
input type=url
ins
isIndex
kbd
label
legend
li
listing
marquee
menu
noBR
ol
p
plainText
pre
q
rt
ruby
s
samp
small
span
strike
strong
sub
sup
textArea
tt
u
ul
var
xmp

 

 

표시:
© 2014 Microsoft. All rights reserved.