jquery - 如何使用jquery提交表单并隐藏和显示图像和按钮

标签 jquery

我正在使用 JQuery

我有以下 html:

HTML 代码:

 <div id="skywardsLogin" style="display: none;">
            <div class="formContainer" id="loginDetails">
                <form action="#" id="frmLogin" class="homeWidget">
                    <table border="0" cellpadding="0" cellspacing="0">
                        <tr>
                            <td class="formLabel" width="100">
                                <label for="skywardsNumber" title="Skywards Number">
                                    Skywards Number</label></td>
                            <td>
                                <input class="formField" id="skywardsNumber" name="skywardsNumber" size="25" type="text" /></td>
                            <td class="formLink">
                                <a class="iconHelpBox" href="#">Forgot number</a></td>
                        </tr>
                        <tr>
                            <td class="formLabel">
                                <label for="password">
                                    Password</label></td>
                            <td>
                                <input class="formField" id="password" name="password" size="25" type="password" /></td>
                            <td class="formLink">
                                <a class="iconHelpBox" href="#">Forgot password</a></td>
                        </tr>
                    </table>
                </form>
            </div>
            <div class="horRuleWhite">
                <hr />
            </div>
            <div class="continueBar">
                <div class="continueBarLeft">
                    <p class="validateTips" style="color: Red">
                    </p>
                </div>
                <div class="continueBarRightButton">
                    <input alt="Log In" id="loginButton" src="system/images/form_buttons/button_log_in.gif"
                        title="Log In" type="image" />
                    <div id="ajaxloading" style="display: none">
                        <img align="absmiddle" src="system/images/spinner.gif" alt="Processing..."/>&nbsp;Processing...
                    </div>
                </div>
            </div>
        </div>

JQuery 代码:

/ Dialog            
    $('#skywardsLoginLink').click(function(){
        $('#skywardsLogin').dialog({
            autoOpen: true,
            width: 450,
            modal: true,
            title: 'Login to your Skywards Account'
        });
        if($('#skywardsLogin').is(':visible')) {
            hideSelect();
        } else {
            showSelect();
        }
    });

//Login Button Clicked
$('#loginButton').click(function()
{
    var bValid = true;
    bValid = bValid && checkLength( skywardNo, "Skyward No", 3, 16 );
    bValid = bValid && checkLength( password, "password", 5, 16 );

    if ( bValid ) 
    {      
       $("#loginDetails > form").submit();
        allFields.val("");
        tips.text("");
    }
});

 //Submitting the form
$("#loginDetails > form").submit(function()
{  
    //Hiding the Login button
    ("#loginButton").hide();

    //Showing the ajax loading image
    ("#ajaxloading").show();

    // 'this' refers to the current submitted form  
    var str = $(this).serialize();   
    // -- Start AJAX Call --

    $.ajax({  
        type: "POST",
        url: "Login.aspx",  // Send the login info to this page
        data: str,  
        success: function(msg)
        {  

            $("#loginDetails").ajaxComplete(function(event, request, settings){  

             // Show 'Submit' Button
            $('#loginButton').show();

            // Hide Gif Spinning Rotator
            $('#ajaxloading').hide();  

             if(msg == 'OK') // LOGIN OK?
             {  
                $('a.modalCloseImg').hide();  

                $(this).html(login_response); // Refers to 'status'

            // After 3 seconds redirect the 
            //setTimeout('go_to_private_page()', 3000); 
         }  
         else // ERROR?
         {  
             var login_response = msg;
             $('#login_response').html(login_response);
         }  

     });  

     }  

    });  

    // -- End AJAX Call --

    return false; 
});      

我正在尝试调用模式弹出对话框,其中它将验证用户名和密码,如果所有内容都有效,则将提交表单#loginDetails >表单,表单正在提交,但是它在下面的行给出错误(#loginButton".hide 不是函数)

//Hiding the Login button
    ("#loginButton").hide();

    //Showing the ajax loading image
    ("#ajaxloading").show();

知道可能是什么原因吗,因为我们在我的 html 中获得了这两个 ID。

谢谢。

最佳答案

错过了这些行之前的$

//Hiding the Login button
    $("#loginButton").hide();

    //Showing the ajax loading image
    $("#ajaxloading").show();

关于jquery - 如何使用jquery提交表单并隐藏和显示图像和按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4447370/

相关文章:

javascript - 有两个表单不是使用 javascript 提交的

javascript - 使用 jQuery 查找和替换 HTML

javascript - jQuery ajax,等到 beforeSend 动画结束

javascript - 通过 jquery 或 javascript 限制复选框检查

jquery - jQuery 中的 slideDown() 是否不适用于 body 和 html 元素?

javascript - 单击图像时淡出图像(具有 id)(因此在单击之前 ID 是未知的)

javascript - 查找 jquery 插件/函数是否可用。 $.pluginName() 和 $().pluginName() 之间的区别

javascript - JQuery Draggable 以编程方式拖动到位置

jquery - Slimbox V2 升级到 jQuery 1.9.1 时出现错误

javascript - 我无法检查文件的扩展名