如何从jQuery对话框按钮部分内部修改当前选择器的id属性?

我想用“间接”类的id中的用户名字符串替换jquery对话框输入字段中用户指定的用户名。问题是我无法使用this.id = this.id.replace(’username’,myvalue)coz $ this this refer refer到jquery对话框ui里面的输入元素….请帮我用其他任何方法对它进行排序

  

================================================== ==============================

 $(.indirect).click(function(){ $("#dialog").dialog({ buttons: { "OK": function() { if($('#username').val() == '') { $('#username').focus(); } else { var myvalue= $("#username").val(); var provider_url_post= // replace "username" in google id with myvalue alert(provider_url_post); }) 

您的JS中有一堆语法错误,但假设您的实际代码中不存在这些错误:

 $('.indirect').click(function() { var self = this; $("#dialog").dialog({ buttons: { "OK": function() { if (!$('#username').val()) { // just check the truthiness $('#username').focus(); } else { var myvalue = $("#username").val(); self.id = self.id.replace('username', myvalue); } } } }); });​