无法获取jQuery-UI模态对话框来设置提交值

时间:2010-11-06 01:16:09

标签: jquery regex jquery-ui modal-dialog

我有一个jQuery模式对话框,提示用户输入他们的OpenID用户名。问题是我无法获得“提交”功能来正确设置用户名

<script>
    var OpenIDAddress;

    $('.openid_btn').click(function () {
        switch ($(this).text()) {
            case "Google":
                $("#openid_identifier").val("https://www.google.com/accounts/o8/id");
                break;
            case "Yahoo!":
                $("#openid_identifier").val("http://yahoo.com/");
                break;
            case "myOpenID":
                OpenIDAddress = 'http://{username}.myopenid.com/';
                openOpenIDDialog();
                break;
        }
    });

    // Manages the username window
    $("#openid-username-dialog").dialog({
        autoOpen: false,
        resizable: false,
        height: 140,
        modal: true,
        buttons: {
            'Submit': function () {
                OpenIDAddress = OpenIDAddress.replace(/{username}/, $("openid-username").val());
                $("#openid_identifier").val(OpenIDAddress);
                $(this).dialog('close');
            },
            Cancel: function () {
                $(this).dialog('close');
            }
        }
    });


    // Opens the Username Input Window
    function openOpenIDDialog() {
        $('#openid-username-dialog').css('display', 'inherit');
        $('#openid-username-dialog').dialog('open');

        return false;
    }
</script>

基本上我正在做的是使用case语句来决定用户点击哪个openID。

如果openID Provider需要用户名,那么我打开一个请求用户名的模式对话框。

然后,当用户按下提交时,我想运行一个正则表达式,用用户条目替换{username}

我遇到的问题是当你点击提交时,我在输入中得到以下内容

  

http://undefined.myopenid.com/

1 个答案:

答案 0 :(得分:1)

@ @ $%^

的烧伤

我忘了添加哈希标记

OpenIDAddress = OpenIDAddress.replace(/{username}/, $("openid-username").val());

应该是

OpenIDAddress = OpenIDAddress.replace(/{username}/, $("#openid-username").val());