分享一个双击后编辑并AJAX提交保存的脚本

 

    <script type="text/javascript">
        jQuery(document).ready(function () {
            jQuery(".wordsupdate").dblclick(function () {
                id = jQuery(this).attr('id');
                text = jQuery(this).text();
                if (text) {
                    jQuery(this).html("<textarea style='width:200px;height:50px;' name=" + id + " >" + text + "</textarea>");
                    jQuery(".wordsupdate > textarea").focus().blur(function () {
                        jQuery.ajax({
                            type: "POST",
                            url: "/Home/Update",
                            data: "ID=" + id + "&Str=" + jQuery("#" + id + " > textarea").val(),
                            success: function (msg) {
                                jQuery("#" + id).html(jQuery("#" + id + " > textarea").val());
                            },
                            error: function (msg) {jQuery("#" + id).text(msg);}
                        });
                    })
                }
            })
        })  
    </script>

 

posted @ 2012-02-10 11:33  Care健康  阅读(218)  评论(0编辑  收藏  举报
版权
作者:Bober Song

出处:http://bober.cnblogs.com

Care健康:http://www.aicareyou.com

推荐空间:华夏名网

本文首发博客园,版权归作者跟博客园共有。

转载必须保留本段声明,并在页面显著位置给出本文链接,否则保留追究法律责任的权利。