0

私はjavascriptにかなり慣れていません。以下は私のjavascriptコードです。いくつかのクリック可能なクラスがありますid。例:

<a href="#" id="15" class="firefly-button lfloat"><div class="contentBoxes captionfull">

ユーザーがそれをクリックした場合、変数をとして保存したいと思います"showf15"["show"+first-character of clicked-class+id]

これを達成するために、私は次の行を書きました:

c = "show"+$(this).charAt(0)+this.id;

私のjvascriptコードは次のとおりです。

$(function () {
        $(".primavera-button, .lectures-button, .firefly-button, .argentum-button, .workshops-button, .exhibitions-button").click(function (e) {
            c = "show"+$(this).charAt(0)+this.id;
                e.stopPropagation();
            $.ajax({
                type: "POST",
                url: "../fetchevents.php",
                dataType: "json",
                data: {
                    id: c
                },
                ....

ただし、機能していないようです。

変数などを取得できる場合cshowl15データベーステーブルにはc= idを持つテキストデータが含まれており、結果としてjsonで取得できます。

4

1 に答える 1

1

$(this)クラスの名前ではなく、jQueryでラップされた要素です。

使用する

"show"+this.className[0]+this.id;
于 2013-02-20T08:16:24.493 に答える