C# 只需稍加修改的Jquery选择器选项

C# 只需稍加修改的Jquery选择器选项,c#,jquery,asp.net,ajax,json,C#,Jquery,Asp.net,Ajax,Json,我正在asp.net中开发一个讨论面板,其中我将jquery选择器选项与两个类一起使用 $("#plblDisAgreeProblem", "plblDisAgreeComment").click(function(){ var str = { problemID: $("#problemID").val(), empID : $("#empID").val(), commentID : -1 }

我正在asp.net中开发一个讨论面板,其中我将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
                  {




                }
            });


        })
$(“#plbldiscoverproblem”,“plbldiscovercomment”)。单击(函数(){
var str={
problemID:$(“#problemID”).val(),
empID:$(“#empID”).val(),
注释ID:-1
}
$.ajax({
键入:“获取”,
url:“”,
数据:str,
错误:函数(msg){
警报(“错误2”+消息);
},
成功:功能(msg){
var out=msg.split(
); if(out[1]=“不同意:True”) { 警惕(“你已经不同意这个问题了。”); } 其他的 { } }); })
我想知道如果div的类是'plbldiscoverProblem',那么JSon commentID中的类应该是-1,如果div的类是'plbldiscoverComment',那么JSon commentID中的类应该是this.id,但是我怎么做呢

请帮帮我

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

  if(this.className == 'plblDisAgreeComment') {
     str.commentID = this.id;
  } else {
   // do other
  }
  ......
  ......
});
类选择器缺少点(.)

使用此is()函数:

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

我相信这应该行得通(无法从我现在的位置进行测试)。

首先,让我们修复类选择器中缺少的点。请参见下文

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

   if ($(this).hasClass('plblDisAgreeComment') {
       str.commentID = this.id;
   } 
然后可以使用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('plbldiscoverproblem')
,因为它默认为-1。

这应该可以做到:(还修复了一些语法错误)

$(“#plbldiscoverproblem”、“.plbldiscovercomment”)。单击(函数(){
var str={
problemID:$(“#problemID”).val(),
empID:$(“#empID”).val(),
commentID:$(this.hasClass('plblDiscoverComment')?this.id:-1
};
$.ajax({
键入:“获取”,
url:“”,
数据:str,
错误:函数(msg){
警报(“错误2”+消息);
},
成功:功能(msg){
var out=msg.split(
); if(out[1]=“不同意:True”){ 警惕(“你已经不同意这个问题了。”); }else{} }); }); });
关于速度:


但这并不是我问题的答案,亲爱的。如果它有任何其他类,它将失败。类不需要其中的“.”点。这应该可以工作,尽管我会使用“comment”类并交换-1和this.id的顺序-但这只是我的偏好