簡體   English   中英

按下提交按鈕時隱藏 div

[英]Hide the div when the submit button is pressed

我想在按下提交按鈕后永久隱藏<div class="frm_button_submitt" id="hideOnSubmit">

我正在創建一個多步表單,我的意思是當用戶跳過第一步時,div 消失

 <div class="frm_submit"> [if back_button]<button type="submit" name="frm_prev_page" formnovalidate="formnovalidate" class="frm_prev_page" [back_hook]>[back_label]</button>[/if back_button] <!-- When you click here for the first time --> <button class="frm_button_submit" type="submit" id="toggle" [button_action]>[button_label]</button> <!-- This div disappears in the following steps --> <div class="frm_button_submitt" id="hideOnSubmit"> <label><input type="checkbox" name="rememberMe" value="true" tabindex="4"><i class="a-icon a-icon-checkbox"></i><span class="a-label a-checkbox-label"> Keep me signed in. <span class="a-declarative" data-action="a-popover" data-a-popover="{&quot;activate&quot;:&quot;onclick&quot;,&quot;header&quot;:&quot;\\&quot;Keep Me Signed In\\&quot; Checkbox&quot;,&quot;inlineContent&quot;:&quot;\
    
    
    

這是一個簡單的解決方案,使用枚舉器,但我無法實現它,有沒有人可以幫助我正確完整地編寫它

 const element = document.getElementById("#"); let clickCount = 0; element.addEventListener("click", (e) => { if(clickCount > 0) return element.style.display = "none"; console.log("Clicked") clickCount++; });

注:點擊次數接下來4次點擊

一張圖來說明問題

您可以使用 css 來管理它。

window.addEventListener('load', () => {
  document.querySelector("#toggle").addEventListener("click", (e) => {
    document.querySelector("body").classList.add('hideTheButton');
  });
})

...然后只有一個 css 規則:

body.hideTheButton #hideOnSubmit{
  display:none;
}

你的問題代碼很笨拙。 但你可以用這種方式隱藏。

<script type="text/javascript">
  function hideDiv() {
    document.getElementById("hideOnSubmit").style.display = "none";
    return true;
  }
</script>

<div class="frm_submit">
  [if back_button]<button type="submit" name="frm_prev_page" formnovalidate="formnovalidate" class="frm_prev_page"
    [back_hook]>[back_label]</button>[/if back_button]

  <!-- When you click here for the first time -->
  <button class="frm_button_submit" type="submit" id="toggle" [button_action]
    onclick="return hideDiv()">[button_label]</button>

  <!-- This div disappears in the following steps -->
  <div class="frm_button_submitt" id="hideOnSubmit">
    <label><input type="checkbox" name="rememberMe" value="true" tabindex="4"><i
        class="a-icon a-icon-checkbox"></i><span class="a-label a-checkbox-label">
        Keep me signed in.
        <span class="a-declarative" data-action="a-popover"
          data-a-popover="{&quot;activate&quot;:&quot;onclick&quot;,&quot;header&quot;:&quot;\&quot;Keep Me Signed In\&quot; Checkbox&quot;,&quot;inlineContent&quot;:&quot;\u003cp>Choosing \&quot;Keep me signed in\&quot; reduces the number of times you're asked to Sign-In on this device.\u003c\/p>\n\u003cp>To keep your account secure, use this option only on your personal devices.\u003c\/p>&quot;}">
          <a id="remember_me_learn_more_link" href="javascript:void(0)" class="a-popover-trigger a-declarative">
            Details
            <i class="a-icon a-icon-popover"></i></a>
        </span>
      </span></label>
  </div>

暫無
暫無

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

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