duanji1043
2012-05-03 18:57
浏览 48

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

I want to replace username string in id of "indirect" class with username specified by users in jquery dialog input field.Problem is i cant use this.id = this.id.replace('username', myvalue) coz $this will refer to the input element inside of jquery dialog ui.... Please help me to sort this out by any other method

<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"/> 

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

$(.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);
})

图片转代码服务由CSDN问答提供 功能建议

我想将id为“indirect”类的用户名字符串替换为jquery对话框输入字段中用户指定的用户名。 问题是我无法使用this.id = this.id.replace('username',myvalue)coz $这将引用jquery对话框ui中的输入元素....请帮我通过任何其他方法对此进行排序

 &lt; img src =“images / AOL_button.png”id ='http://openid.aol.com/username'class =“indirect”/&gt; \  n&lt; img src =“images / google_button.png”id ='https://www.username.google.com/accounts/o8/id'class =“direct”/&gt;  
   
 
 

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

  $(。indirect).click(function(){
 $(“#dialog”)。dialog({
 buttons:{
“OK”:function()  {
 if($('#username')。val()==''){
 $('#username')。focus(); 
} else {
 var myvalue = $(“#  username“)。val(); 
 var provider_url_post = //将google id中的”username“替换为myvalue 
 alert(provider_url_post); 
})
   
 
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dqm74406 2012-05-03 19:03
    已采纳

    You've got a bunch of syntax errors in your JS, but assuming those don't exist in your actual code:

    $('.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);
                    }
                }
            }
        });
    });​
    
    已采纳该答案
    打赏 评论

相关推荐 更多相似问题