2012-04-16 4 views
0

私はdiv要素のクラスが、その後「plblDisAgreeProblem」の場合、私が欲しい、私は二つのクラスわずかな変更でjQueryのセレクタのオプション

$("#plblDisAgreeProblem", "plblDisAgreeComment").click(function(){ 
var str = { 
      problemID: $("#problemID").val(), 
      empID : $("#empID").val(), 
      commentID : -1 
     } 
     $.ajax({ 

      type: "GET", 
      url: "<%= Url.Action("GetStatus", "Discussion") %>", 
      data: str, 
      error: function(msg){ 
        alert("error2" + msg); 
       }, 
       success: function (msg) { 

        var out = msg.split("<br/>"); 
        if (out[1] == "DisAgree: True") 
        { 
         alert("You are already disagree to this problem."); 
        } 
        else 
        { 




       } 
      }); 


     }) 

とjqueryのセレクタオプションを使用していたにasp.netでのパネルディスカッションを開発していますJSONのcommentIDは-1でなければなりません。divのクラスが 'plblDisAgreeComment'の場合、JSonのcommentIDはthis.idでなければなりませんが、どうすればいいですか?

私のクラスセレクタの

答えて

1

まず

、そして、あなたは以下を参照してください。..クリックされた要素は、指定されたクラスからであるかどうかを確認するためにhasClass機能を使用することができます
$("#plblDisAgreeProblem", ".plblDisAgreeComment").click(function(){ 

、以下を参照してください...あなたのクラスセレクタでドット抜けを修正することができます
var str = { 
     problemID: $("#problemID").val(), 
     empID : $("#empID").val(), 
     commentID : -1 
    } 

    if ($(this).hasClass('plblDisAgreeComment') { 
     str.commentID = this.id; 
    } 

else if of ('plblDisAgreeProblem')のデフォルト値は-1であるため、この値は必要ありません。

+0

hasClass "。"は必要ありません。それにドットをつける –

+0

@ MarkSchultheissあなたは正しいです。更新しました。ありがとうございました! –

0
$("#plblDisAgreeProblem", ".plblDisAgreeComment").click(function(e) { 
    .... 
    .... 

    if(this.className == 'plblDisAgreeComment') { 
    str.commentID = this.id; 
    } else { 
    // do other 
    } 
    ...... 
    ...... 
}); 

ドット抜けを助けてください

+0

しかし、これは私の問題を愛するの答えではありません。スピードのための参照では

$("#plblDisAgreeProblem", ".plblDisAgreeComment").click(function() { var str = { problemID: $("#problemID").val(), empID: $("#empID").val(), commentID: $(this).hasClass('plblDisAgreeComment') ? this.id : -1 }; $.ajax({ type: "GET", url: "<%= Url.Action("GetStatus", "Discussion") %>", data: str, error: function(msg) { alert("error2" + msg); }, success: function(msg) { var out = msg.split("<br/>"); if (out[1] == "DisAgree: True") { alert("You are already disagree to this problem."); } else {} }); }); }); 

を(だけでなく、構文エラーのカップルを固定しました) 。 – Billz

+0

他のクラスがある場合は失敗します –

1

使用これで()関数(。):

commentID : $(this).is(".plblDisAgreeProblem") ? -1 : this.id 

私は、これは動作するはずと信じては(テストすることはできません私は今どこにいるのか)。

+0

"comment"クラスを使用し、-1とthis.idの順番を入れ替えることができますが、これはうまくいくはずですが、これは自分の好みの設定です –

関連する問題