ajax 无刷新更新内容
本例无更新数据库的部分,如果想要更新数据库可以参考本站其他的类似效果,例如《jquery表格可编辑修改表格里面的值,点击td变input无刷新更新表格》
XML/HTML Code
- <ul class="users">
- <li>
- <input type="text" name="user[]" value="Jimmi Westerberg" />
- </li>
- <li>
- <input type="text" name="user[]" value="Buddy Carlson" />
- </li>
- <li>
- <input type="text" name="user[]" value="Steve Martin" />
- </li>
- <li>
- <input type="text" name="user[]" value="Babe Ruth" />
- </li>
- </ul>
- <br/>
- <a name="save_on_the_go"></a>
- This will give the following editme field:
- <input type="text" id="most_options" value="Jimmi Westerberg" />
- <br/>
- </div>
- <script type="text/javascript">
- $(document).ready(function() {
- $('ul.users input').editme();
- // uses the autosave option
- $('#save_me').editme({
- 'autosave': function(data_to_save) {
- $.post(
- 'save_data.json',
- data_to_save, 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 more.
- $('#save_me').editme('saved');
- }
- );
- }
- });
- // uses most options as an example
- $('#most_options').editme({
- 'edittext':'Edit me!',
- 'removetext': 'Delete this row',
- 'removeable':true,
- 'savetext':'Save for later...',
- 'canceltext':'Oopsie, cancel!'
- });
- });
- </script>
原文地址:http://www.freejs.net/article_biaodan_292.html