2016-03-09 43 views
0

我試圖在單擊Gridview中的向上/向下箭頭後移動行索引,不幸的是,當我進入我的Jquery時,它似乎只是在我的Repeater內部獲得了一個GridView的句柄。帶有通配符的JQuery屬性選擇器

我傳遞得到該行手柄的ID是:

$('#Repeater1_ctl16_MeetingSumaryGridview1 a.move').click(function() { 

的問題是,「ctl16」變化,這取決於GridView的我從選擇的箭,我希望能夠在這裏放置一個通配符,以獲得我選擇的箭頭的gridview句柄。

下面是我的jQuery代碼:

$(document).ready(function() { 
    $('#Repeater1_ctl16_MeetingSumaryGridview1 a.move').click(function() { 
     var row = $(this).closest('tr'); 
     if ($(this).hasClass('up')) { 
      var headrChck = row.prev() 
      if (headrChck[0].cells['1'].tagName != 'TH') { 
       row.prev().before(row); 
      } 
     } 
     else { 
      row.next().after(row); 
     } 
    }); 
}) 

我已經試過,我在網上找到的,但所有的通配符我似乎使用沒有得到處理許多事情。

我想知道如果我能得到一些關於此的幫助/建議,任何感謝,感謝您提前。

回答

1

如果你看看documentation,你會發現^$是jQuery中的通配符。

我覺得你的情況應該是這個樣子:

$("[id^=Repeater1]").click(function() { 
     var row = $(this).closest('tr'); 
     if ($(this).hasClass('up')) { 
      var headrChck = row.prev() 
      if (headrChck[0].cells['1'].tagName != 'TH') { 
       row.prev().before(row); 
      } 
     } 
     else { 
      row.next().after(row); 
     } 
    }); 

TL; DR;

  • 使用*contains

  • 使用^starts with

  • 使用$end with

當心比較是大小寫敏感的。

+1

非常感謝! –