繁体   English   中英

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

[英]How do you modify the id attribute of current selector from inside of a jQuery dialog button section?

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

<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);
})

您的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);
                }
            }
        }
    });
});​

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM