现在意识到我也想要分开并获得所有角色,然后才能获得#34; chkOut"
GridView1__ctl2_chkOut
所以我想要GridView1__ctl2_
我原来的问题:
Needing to get only part of the ID everything after last underscore
LOOP回答我喜欢的另一个问题,但我不知道完整的ID名称。
<td>
<input id="GridView1__ctl2_chkOut" type="checkbox" name="GridView1:_ctl2:chkOut" checked="checked" class="out">
</td>
<td>
<input id="GridView1__ctl2_chkYes2" type="checkbox" name="GridView1:_ctl2:chkYes2" checked="checked" class="yesno">
</td>
<td>
<input id="GridView1__ctl2_chkNo2" type="checkbox" name="GridView1:_ctl2:chkNo2" class="yesno">
</td>
答案 0 :(得分:2)
试试这个:
var text = "GridView1__ctl2_chkOut";
var firstHalf = text.substring(0, text.lastIndexOf('_') + 1);
var secondHalf = text.substring(firstHalf.length, text.length);
答案 1 :(得分:1)
试试这个:
var str = 'GridView1__ctl2_chkOut';
console.log(str.substring(0,str.lastIndexOf('_')+1));
答案 2 :(得分:0)
var str = "GridView1__ctl2_chkOut"
str.split('chkOut')[0]