2017-07-18 71 views
0

如何使用具有两个属性的元素作为标识符?我在这里得到了这个带有id和name标识符的tr元素。JQuery使用名称获取元素AND ID

<tr class="danger" id="event_row" name="'.$result["id"].'" data-tooltip="#popupboxm"> 

我想用它来此事件:

$(document).on('click', '#evnt_can', function() { 
      var item = this; 
      var table_row = //the two-identifier element will be use in this variable. 
      var option1Value = $(this).data("value"); 
      var option2Value = $(this).data("status"); 
      $.ajax({ 
       async: false, 
       url : "models/ajaxReq/req_evntcan.php", 
       type : 'POST', 
       data : {option1Value, option2Value}, 
       dataType: "text", 
       success : function() { 
        if (option1Value == 0){ 
         $(table_row).attr("class", "danger"); 
         $(item).html("Cancel Event"); 
        } 
        else if (option1Value == 1){ 
         $(table_row).attr("class", "info"); 
         $(item).html("Reassign Event"); 
        } 
       }, 
       error : function() { 
        console.log(xhr.responseText); 
       } 
      }); 
     });` 
+2

ID就足够了因为ID应该在上下文中是唯一的 – guradio

+2

只需使用ID来定位元素。它是(应该是)唯一的 – Phil

+2

你可以通过ID和名字一起选择''#idHere [name =“nameHere”]'',但是正如已经指出的那样,ID应该是唯一的,因此只有它有意义如果您不想选择只有一个或其他ID和名称的元素,则两者都选择。 – nnnnnn

回答

0

好了,我想你可以使用自定义属性来合并它们,然后使用自定义属性作为标识符

+0

试过这种方法,使我的一天变得更加混乱。 – Calvin

+0

抱歉。 –