1

私はjQueryTag-Itスクリプトを使用しています。ここで表示できます:

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

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

誰かがタグを追加すると、それがDBに挿入されるように、postリクエストをphpスクリプトに正常に追加しました。

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

4

1 に答える 1

1

削除されたタグにアクセスできるように変更されたコードは次のとおりです。

xの)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/でのデモ

于 2011-12-04T22:38:35.273 に答える