質問

私はjquery tag-itスクリプトを使用していますが、ここで見ることができます:

http://levycarneiro.com/projects/tag-it/example.html

スクリプトには、元々、追加されたタグの投稿を送信したり、ユーザーが削除したりするタグを削除するオプションは付属していません。

誰かがタグを追加したときにDBに挿入するように、PHPスクリプトにPOSTリクエストを正常に追加しました。

問題は、誰かが「x」ボタンをクリックしてタグの1つを削除すると、実際のタグ値を取得する方法を見つけることができないようです。

役に立ちましたか?

解決

これが修正されたコードです。これが削除されるタグにアクセスできるようにすることができます。

の中に click ハンドラー(バツ)

if (e.target.tagName == 'A') {
            // Removes a tag when the little 'x' is clicked.
            // Event is binded to the UL, otherwise a new tag (LI > A) wouldn't have this event attached to it.
            var tag = $(e.target).parent();
            //console.log( tag.children('input').val() ); // this line extracts the tag value
            tag.remove();
        }

とで keypress ハンドラーの使用

if (tag_input.val() == "") {
                // When backspace is pressed, the last tag is deleted.
                var tag = $(el).children(".tagit-choice:last");
                // console.log( tag.children('input').val() ); // this line extracts the tag value
                tag.remove();
            }

デモで http://jsfiddle.net/gaby/yyhtu/1/

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top