在jQuery的帮助下修改元素的ID


modify id of an element with the help of jquery

我想在jquery的帮助下修改元素ID

<img src="images/AOL_button.png" id='http://openid.aol.com/***username***' class="indirect" />
<img src="images/google_button.png" id='https://www.***username***.google.com/accounts/o8/id' class="direct"/> 

所以使用 jQuery 我想根据条件将"用户名"的值更改为其他值

$(.direct).click(function(){
   var username=userA;
   // replace username from id here
})
$(.direct).click(function(){
   var username=userB;
   // replace username from id here
})

尝试如下,

$('.direct').click(function(){
   var username=userA;
   //            ^--assuming userA is a var in scope 
   //            if it is a string, just use it below as "userA"(including the quotes)
   this.id = this.id.replace('***username***', username);
});