LoginSignup
9
10

More than 5 years have passed since last update.

jQueryを使ってDOM要素をクリックしたときに編集できるようにする

Posted at

jQueryを使って「inplace editor」を作る。

(function(documet){

    $(document).ready(function(){
           $(target_id).click(edit_togle());
    });


    function edit_togle(){
        var edit_flag = false;
        return function(){
            if(edit_flag) return;
            var $input = $("<input>").attr("type","text").val($(this).text());
            $(this).html($input); 

            $("input", this).focus().blur(function(){
                save($(this).val());
                $(this).after($(this).val()).unbind().remove();
                edit_flag = false;
            });
            edit_flag = true;
        }
    }    

    function save(value){
        alert(""+value+"」を保存しました"); //保存する処理をここに書く
    }
})(document);

参考
jQueryを使ってテーブルのセルをクリックしたときに編集できるようにする(Edit in Place)

9
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
10