How to make a div with a blinking cursor and editable text without using <input>?

后端 未结 6 1845
既然无缘
既然无缘 2020-12-31 11:34

I need to make a div layer so that when you click on it you will have your cursor there blinking and you can insert/delete text just like

相关标签:
6条回答
  • 2020-12-31 12:06

    You can make the div editable by setting its contentEditable attribute / property to true. However, for anything that is slightly more powerful or flexible then very basic editing, you might want to look at existing solutions such as:

    • TinyMCE
    • Kevin Roth's RTE
    • The YUI editor
    0 讨论(0)
  • 2020-12-31 12:07

    as I understand your problem, you can resove it by adding textarea into your div. It is very simply to make this textarea autosize to occupy whole div area and looks like this div.

    As for contentEditable, I have seen some browsers, supported this feature for div-element and does not. Anyway, you can use iframe in your div. It's document-element can have contentEditable.

    0 讨论(0)
  • 2020-12-31 12:07

    contenteditable attribute could be used for this purpose. Following code line has been tested in IE7 and Firefox 3.0.10. One part, I have noticed that this attribute should be used in lower case only; else it wont work in Firefox.

    <div id="Div_ID" contenteditable="true" tabindex="0">
       Enter text here
    </div>
    
    0 讨论(0)
  • 2020-12-31 12:14

    DIV element has (other elements as well) contentEditable property that you can set in Javascript to true.

    getElementById('YourDiv').contentEditable = true;
    
    0 讨论(0)
  • 2020-12-31 12:26

    I suggest you to use a textarea, and if that's not enough, use a WYSIWYG editor like tinyMCE or FCKeditor.

    0 讨论(0)
  • 2020-12-31 12:27

    Jquery can be used like this:

    $.('#yourDiv').click(function() {
        $(this).attr('contenteditable', 'true');
    });
    
    0 讨论(0)
提交回复
热议问题