簡體   English   中英

提交帳戶后使用jQuery隱藏按鈕

[英]Hide button with jQuery after submit Account

#email和客戶#first / lastname具有值(成功保存)#submitAccount要隱藏時,我嘗試隱藏一個提交按鈕

工作代碼:

                {literal}
            <script>
                $(document).ready(function () {
                            $("#submitGuestAccount").click(function () {
                             if($("#email").val().trim().length>0 && $("#customer_firstname").val().trim().length>0 && $("#customer_lastname").val().trim().length>0 )   {
                                    $('#new_account_form p.submit').hide();
                                }
                            });
                });
            </script>
            {/literal}
            <p class="submit">
                <input type="submit" class="exclusive button" name="submitAccount" id="submitAccount" value="{l s='Save'}" />
            </p>

但是如何添加過濾器-當頁面加載並

  if($("#email").val().trim().length>0 && $("#customer_firstname").val().trim().length>0 && $("#customer_lastname").val().trim().length>0 ) 

再次隱藏按鈕。 現在,當我刷新頁面按鈕時再次顯示嗎?

請通過添加});關閉准備});

$(document).ready(function () {
            $("#submitAccount").click(function () {
                if ($("#email").val() && $("#customer_firstname").val() && $("#customer_lastname").val()) {
                    $('#submitAccount').hide();
                }
            });
});

這是更正的代碼:

<script>
        $(document).ready(function () {
                $("#submitAccount").click(function () {
                    if ($("#email").val() && $("#customer_firstname").val() && $("#customer_lastname").val()) {
                        $(this).hide();
                    }
                }); 
    </script>

    <p class = "submit"> <input type = "submit" class="exclusive button" name="submitAccount" id = "submitAccount" value = "{l s='Save'}"/></p>

將條件更改為

if($("#email").val().trim().length>0 && $("#customer_firstname").val().trim().length>0 && $("#customer_lastname").val().trim().length>0 )   {
    $('#submitAccount').hide();
}

希望能有所幫助。

我認為Mathias是正確的..您錯過了ready函數的關閉。.有時,我使用簡單的已知技巧來查看我的代碼是否有錯誤。.這添加了alert方法

例如添加

$(document).ready(function () {
            $("#submitAccount").click(function () {
                if ($("#email").val() && $("#customer_firstname").val() && $("#customer_lastname").val()) {
                    $('#submitAccount').hide();
alert('after the hiding method');
                }
}
            });

當未調用該警報方法時,您的代碼缺少某些內容

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM