简体   繁体   English

单击按钮时如何从页面(Bootstrap 4)中隐藏或删除搜索表单?

[英]How to hide or remove the search form from the page (Bootstrap 4) on clicking a button?

How can I get this search form and the Search Button to disappear from the page, since it will be replaced by a Thank you message?我怎样才能让这个搜索表单和搜索按钮从页面上消失,因为它将被感谢信息所取代?

<div class="row">
      <div class="col">

        <!-- ## SEARCH FORM ------------------------------------------------ -->
        <form id="search-form" class="form-inline" onsubmit="handleFormSubmit(this)">
          <div class="form-group mb-2">
            <label for="searchtext">Enter your email</label>
          </div>
          <div class="form-group mx-sm-3 mb-2">
            <input type="text" class="form-control" style='width:310px' id="searchtext" name="searchtext" placeholder="Search Text">
          </div>
          <button type="submit" class="btn btn-primary mb-2">Search</button>
        </form>
        <!-- ## SEARCH FORM ~ END ------------------------------------------- -->

      </div>
    </div>

I was trying something like:我正在尝试类似的东西:

//HANDLE FORM SUBMISSION
function handleFormSubmit(formObject) {
  google.script.run.withSuccessHandler(createTable).processForm(formObject);
}
function saveData() {
  var searchForm = document.getElementById('search-form')
  var page = document.getElementById("page");
  var table = document.getElementById("dtable");

  //document.getElementById("search-form").reset();
  page.innerHTML = "";
  search-form... = ""//????
  table.innerHTML = "<h4>Thank you!</h4>";
}

You have onsubmit="handleFormSubmit(this) so you better to add your <h4>Thank you!</h4> code inside of handleFormSubmit() , but anyway, you may do it like this:你有onsubmit="handleFormSubmit(this)所以你最好在handleFormSubmit() () 中添加你的<h4>Thank you!</h4>代码,但无论如何,你可以这样做:

<div class="row">
  <div class="col">
    <form id="search-form" class="form-inline" onsubmit="handleFormSubmit(this)">
      <div class="form-group mb-2">
        <label for="searchtext">Enter your email</label>
      </div>
      <div class="form-group mx-sm-3 mb-2">
        <input type="text" class="form-control" style='width:310px' id="searchtext" name="searchtext" placeholder="Search Text">
      </div>
      <button type="submit" class="btn btn-primary mb-2" id="searchButton" onclick="saveData();">Search</button>
    </form>
  </div>
</div>

<script type="text/javascript">
    function insertAfter(newNode, existingNode) {
      existingNode.parentNode.insertBefore(newNode, existingNode.nextSibling);
    }

    function saveData() {
      var searchForm = document.getElementById('search-form');
      var searchButton = document.getElementById("searchButton");

      var thankYouDiv = document.createElement('div');
      thankYouDiv.innerHTML = "<h4>Thank you!</h4>";

      insertAfter(thankYouDiv,  searchForm.lastElementChild);
    }
</script>
var searchForm = document.getElementById('search-form');
var page = searchForm.parentElement;

// Set new result
page.innerHTML = 

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

相关问题 如果用户单击“返回”,如何在上一页中隐藏引导程序模式? - How to hide a bootstrap modal on the previous page if user comes in clicking BACK? 如何通过单击按钮隐藏具有动态生成的ID的表单 - How to hide form with dynamically generated ID by clicking a button 单击按钮时如何在另一个页面中弹出引导警报 - How to make bootstrap alert popup in another page when clicking on a button 单击菜单按钮时隐藏页面滚动 - Hide page scroll when clicking menu button 如何在Twitter引导程序轮播中加载页面后隐藏左键? - How to hide left button after page load in Twitter bootstrap carousel? 单击搜索按钮并在同一页面上打印结果后,如何同时保留搜索查询框和字母搜索 - How to retain both the search query box and the alphabetical search after clicking on search button and printing result on the same page 单击提交按钮后如何在不通过服务器的情况下如何从HTML页面的形式获取数据到另一个页面 - How to get data from a form of an Html page to another page after clicking submit button, without going through the Server 如何通过单击按钮删除包装 - How to remove packery by clicking on button 从按钮引导登录表单div-单击表单后无法保持打开状态 - bootstrap login form div from button - not staying open after clicking form 如何隐藏表单中的按钮 - How to hide a button in form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM