0

我想在 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
})
4

1 回答 1

5

尝试如下,

$('.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);
});
于 2012-05-03T18:15:42.897 回答