Javascript to make input field in edit mode(insert mode)

前端 未结 4 1833
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-12 01:19

How is it possible to make a input field editable in javascript. I mean onFocus putting it in insert mode so that values can be overwritten. Any suggestions ???

4条回答
  •  灰色年华
    2021-01-12 01:59

    EDIT: May be totally off-topic, depending on the meaning behind the question.

    If you can use jQuery, Jeditable is a nice plugin to do just that.

    If you must roll your own code, take a look at how that plugin works and use it as a starting point.

    Basically, the steps are:

    1. onFocus/onClick - swap your field with an input.
    2. When the user is "done" (hit Enter, click a button), push the result back to the server via Ajax.
    3. When your request completes, update the interface with the new value, hiding the input.

提交回复
热议问题