editme.js

editme is a small jQuery plugin designed to make large forms more usable.

editme hides the input field, shows a nice labeled version of the data in the input field and adds an edit button.

Hiding input fields in forms

Sometimes a long form needs to have dynamic content.
If you have a list of users, you can edit them

In order to achive this, just have a list of input fields with the type text:
<div class="users">
  <input type="text" name="user[]" value="Jimmi Westerberg" />
  <input type="text" name="user[]" value="Buddy Carlson" />
  <input type="text" name="user[]" value="Steve Martin" />
  <input type="text" name="user[]" value="Babe Ruth" />
</div>

And add the following script:
<script type="text/javascript">
  $(document).ready(function() {
    $('ul.users input').editme();
  });
</script>

Save on the go!

Do you want the data to be saved on the fly? (AJAX and other buzzwords here)

Simply use the "autosave" option, with the function for saving the new data entered.

<script type="text/javascript">
  $(document).ready(function() {
    $('#save_me').editme({
      // REMEMBER dataToSave (call it what you want), else the data cannot be passed to your custom function
      'autosave': function(dataToSave) { 
        // implement any way of saving here... i'm using ajax post in this example
        $.post(
          'save_data.json',
          dataToSave,
          function(data) {
            // do whatever you want with the data returned
            // ...


            // REMEMBER TO CALL THIS METHOD!
            // else the display view is not shown and it will be stuck at the 
            // edit mode.
            $('#save_me').editme('saved');
          }
        );
      }
    });
  });
</script>

Options

You can easily customize the editme boxes and even add a remove link!

"Nearly all options used"-example

<script type="text/javascript">
  $(document).ready(function() {
    $('#most_options').editme({
      'edittext':'Edit me!',
      'removetext': 'Delete this row',
      'removeable':true,
      'savetext':'Save for later...',
      'canceltext':'Oopsie, cancel!'
    });
  });
</script>

This will give the following editme field:

Completely styleable!

The editme script adds lots of HTML to give you a good impression. A lot of that has classes on them, for easier styling.

Example HTML output

<div class="editme" id="editme_container_0">
  <div class="editme_view_container" id="view_editme_container_0">
    <span class="data">Jimmi Westerberg</span>
    <span class="edit_link">
      [<a id="edit_link_edit_editme_container_0" class="ajaxlink">edit</a>]
    </span>
  </div>
  <div style="display: none;" class="editme_edit_container" id="edit_editme_container_0">
    <input type="text" value="Jimmi Westerberg" name="user[]">
    <input type="button" id="save_edit_editme_container_0" value="save">
    or <a id="cancel_edit_editme_container_0" class="ajaxlink">cancel</a>
  </div>
</div>
下载代码说明
X关闭

基于jQuery的无刷新实时修改网页Input内容

jQuery无刷新实时修改网页Input的内容,可以把input数据在不经过数据读取的情况下及时修改,增强用户体验,确认修改后再上传数据库。 这种功能估计大家以前都见到过的,特别是在一些用户体验比较好的CMS系统后台内,想编辑某个值的时候,不需要打开值所在的表单,节省用户时间也减少服务器资源浪费,是项比较实用、人性的功能。